Mike W commited on
Commit
d0ae679
·
1 Parent(s): f0821d0

Fix: Initial runtime errors with integration

Browse files
Files changed (1) hide show
  1. server.py +9 -3
server.py CHANGED
@@ -44,15 +44,21 @@ async def handle_audio_input(websocket: WebSocket, input_queue: asyncio.Queue):
44
  while True:
45
  try:
46
  data = await websocket.receive_bytes()
47
- # Convert webm to pcm
48
  process = (
49
  ffmpeg
50
  .input('pipe:0')
51
  .output('pipe:1', format='s16le', acodec='pcm_s16le', ac=1, ar='16k')
52
  .run_async(pipe_stdin=True, pipe_stdout=True, pipe_stderr=True)
53
  )
54
- stdout, stderr = process.communicate(input=data)
55
- await input_queue.put(stdout)
 
 
 
 
 
 
56
  except WebSocketDisconnect:
57
  break
58
  except Exception as e:
 
44
  while True:
45
  try:
46
  data = await websocket.receive_bytes()
47
+ # Use ffmpeg to convert webm/opus audio from browser to raw pcm
48
  process = (
49
  ffmpeg
50
  .input('pipe:0')
51
  .output('pipe:1', format='s16le', acodec='pcm_s16le', ac=1, ar='16k')
52
  .run_async(pipe_stdin=True, pipe_stdout=True, pipe_stderr=True)
53
  )
54
+
55
+ # Write the audio data to ffmpeg's stdin and close it
56
+ process.stdin.write(data)
57
+ process.stdin.close()
58
+
59
+ # Read the converted PCM data from ffmpeg's stdout
60
+ pcm_data = process.stdout.read()
61
+ await input_queue.put(pcm_data)
62
  except WebSocketDisconnect:
63
  break
64
  except Exception as e: