Skip to content

Commit

Permalink
Add an option to write to binary file directly as windows is messing …
Browse files Browse the repository at this point in the history
…up pipes
  • Loading branch information
nicolas-f committed Jan 15, 2024
1 parent 83051c3 commit f27c7c0
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions services/zero_play.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import sys
import zmq
import argparse
import struct

def main():
parser = argparse.ArgumentParser(description='This program read audio stream from zeromq and push to stdout',
Expand All @@ -12,6 +11,8 @@ def main():

parser.add_argument("-p", "--port", help="Port to publish samples", default=10001, type=int)
parser.add_argument("-i", "--interface", help="Interface to publish", default="127.0.0.1", type=str)
parser.add_argument("-o", "--output_file",
help="Instead of output audio into stdout, write into the specified file", default="", type=str)

args = parser.parse_args()

Expand All @@ -23,9 +24,16 @@ def main():

out_buffer = sys.stdout.buffer

while True:
time_bytes, audio_data_bytes = socket.recv_multipart()
out_buffer.write(audio_data_bytes)
if len(args.output_file) > 0:
out_buffer = open(args.output_file, "wb")

try:
while True:
time_bytes, audio_data_bytes = socket.recv_multipart()
out_buffer.write(audio_data_bytes)
finally:
if len(args.output_file) > 0:
out_buffer.close()


if __name__ == "__main__":
Expand Down

0 comments on commit f27c7c0

Please sign in to comment.