[英]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.