如何将我的响应更改为.wav或.mp3文件? [英] how to change my response into .wav or.mp3 file?

查看:242
本文介绍了如何将我的响应更改为.wav或.mp3文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个EchoServer Websocket 代码来连接实时呼叫,它以7 \ x00E \ x00Y \ x00u \ x00 \ x97 \ x00 \等格式提供响应 xb2 \ x00 \ xb9 \ x00 \ xac \ x00 \ x98 \ x00 \ x87 \ x00x \ x00 [\ x00
我的代码:Echoserver.py

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

类WSHandler(tornado.websocket.WebSocketHandler):

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):

如何从我上面提到的响应中写入mp3文件? 任何建议将不胜感激.

How to write the mp3 file from my response what i have mentioned above?? Any suggestions will be highly appreciated.

回复

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

推荐答案

nexmo Websocket连接上的音频格式为LPCM,16位16Khz单声道.

The format of audio on the nexmo websocket connections is LPCM, 16bit 16Khz Mono.

这与WAV大致相同,LPCM是音频的原始流,WAV是带有RIFF标头的文件,后跟原始流. 有许多用于将原始数据转换为WAV的库,例如 https://docs.python .org/2/library/wave.html

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

如果您需要它作为MP3,则寻找将RAW音频转换为MP3的方法,但是我建议您尝试将RAW/WAV发送到VoiceBase,因为您希望获得最佳的转录,而转换为MP3只会丢失数据并添加转换时会稍有延迟,构建MP3文件也可能会受到许可限制.

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.

这篇关于如何将我的响应更改为.wav或.mp3文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆