Reputation: 4915
I am working with Nexmo. I would like to save live stream Nexmo call audio to my disk. I have implemented web socket to read Nexmo's stream. Please find below the code where I append audio to an existing audio file.
#!/usr/bin/env python
# WS server example
import asyncio
import websockets
async def nexmoServer(websocket, path):
audioData = await websocket.recv()
input_filename = "sample_harshit.wav"
output_filename = "new_file.wav"
ifile = open(input_filename,'rb')
ofile = open(output_filename, 'wb')
data = audioData
while data:
ofile.write(data)
data = ifile.read(1024*1024)
ofile.close()
ifile.close()
The audio file's length is updated but audio data is not written in the file.
Upvotes: 0
Views: 2265
Reputation: 148
Atleast this is working fine:
def nexmoServer():
input_filename = "a.wav"
output_filename = "b.wav"
ifile = open(input_filename,'rb')
ofile = open(output_filename, 'wb')
data = ifile.read(1024*1024)
while data:
ofile.write(data)
data = ifile.read(1024*1024)
ofile.close()
ifile.close()
nexmoServer()
Upvotes: 1