问题
I have an EchoServer Websocket code to connect the live call which gives the response in the format like 7\x00E\x00Y\x00u\x00\x97\x00\xb2\x00\xb9\x00\xac\x00\x98\x00\x87\x00x\x00[\x00
My code :Echoserver.py
class WSHandler(tornado.websocket.WebSocketHandler):
def open(self):
print("Websocket Call Connected")
@gen.coroutine
def on_message(self, message):
print ("message====>",message)
watson = yield self.watson_future
if type(message) == str:
watson.write_message(message, binary=True)
else:
data = json.loads(message)
data['action'] = "start"
data['continuous'] = True
data['interim_results'] = True
print (json.dumps(data))
watson.write_message(json.dumps(data), binary=False)
@gen.coroutine
def on_close(self):
print("Websocket Call Disconnected")
def on_watson_message(self, message):
How to write the mp3 file from my response what i have mentioned above?? Any suggestions will be highly appreciated.
Response
7\x00E\x00Y\x00u\x00\x97\x00\xb2\x00\xb9\x00\xac\x00\x98\x00\x87\x00x\x00[\x00(\x00\xf0\xff\xd8\xff\xfd\xffX\x00\xbb\x00\xf8\x00\x04\x01\xf8\x00\xf2\x00\xf8\x00\xf9\x00\xe7\x00\xc4\x00\x99\x00i\x007\x00\t\x00\xea\xff\xdb\xff\xd6\xff\xd0\xff\xca\xff\xca\xff\xd6\xff\xe9\xff\xfa\xff\x04\x00\x05\x00\x06\x00\x0b\x00\x12\x00\x15\x00\x12\x00\x0b\x00\x06\x00\x06\x00\x07\x00\n\x00\x10\x00\x16\x00\x1a\x00\x1a\x00\x18\x00\x16\x00\x12\x00\t\x0
回答1:
The format of audio on the nexmo websocket connections is LPCM, 16bit 16Khz Mono.
This is broadly the same as WAV, LPCM is the raw stream of audio and WAV is a file with a RIFF header followed by the raw stream. There are various libraries for converting a raw data into WAV for example https://docs.python.org/2/library/wave.html
If you need it as MP3 then look for something to convert RAW audio to MP3, however I would suggest that you try sending RAW/WAV to VoiceBase as you want the best transcription possible and converting to MP3 will just loose data and add a delay while you do the conversion, there may also be licensing constraints with building an MP3 file.
来源:https://stackoverflow.com/questions/48665147/how-to-change-my-response-into-wav-or-mp3-file