[英]How to write audio stream to file in python3
我正在与Nexmo合作。 我想将直播Nexmo通话音频保存到磁盘。 我已经实现了Web套接字来读取Nexmo的流。 请在下面的代码中将音频附加到现有音频文件中。
#!/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()
音频文件的长度已更新,但音频数据未写入文件中。
至少可以正常工作:
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()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.