Spaces:
Sleeping
Sleeping
Mike W commited on
Commit ·
d0ae679
1
Parent(s): f0821d0
Fix: Initial runtime errors with integration
Browse files
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 |
-
#
|
| 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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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:
|