我写的代码没有给出我想要的答案。
from wit import Wit
client = Wit("XXXYYYZZZ")
with open('sa.mp3', 'rb') as f:
resp = client.speech(f, {'Content-Type': 'audio/wav'})
print('Yay, got Wit.ai response: ' + str(resp))`
代码给了我"耶,得到Wit。人工智能反应:{"实体":{},"意图":[],"文本":","特征":{}}">
为什么?
最可能的原因是您向Wit发送了错误的格式。要么将文件格式更改为sa.wav,要么将Content-Type更改为audio/mpeg。
- PCM (audio/raw)默认格式
- mp3(音频/mpeg)
- wav(音频/wav)
from wit import Wit
client = Wit("XXXYYYZZZ")
with open('sa.mp3', 'rb') as f:
resp = client.speech(f, {'Content-Type': 'audio/mpeg'})
print('Yay, got Wit.ai response: ' + str(resp))
文档:https://wit.ai/docs/http/20221114/