简体   繁体   English

发送块音频到Wit.ai

[英]Sending Chunked Audio to Wit.ai

I am attempting to use Wit.ai Speech recognition. 我正在尝试使用Wit.ai语音识别。 I have successfully been able to send a wave file to the website for conversion to text but now I am trying to send it in chunks to reduce latency, but whenever I try to do this It gives me the error 我已经成功地将wave文件发送到网站以转换为文本,但是现在我正尝试分块发送它以减少延迟,但是每当尝试执行此操作都会给我错误

"content-type-mismatch"

even though I am still sending a wav file like i said I was in the headers. 即使我仍在发送wav文件,就像我说的是在标题中一样。 Can someone take a look at my code and tell me what I am doing wrong? 有人可以看一下我的代码并告诉我我做错了什么吗? I appreciate it. 我很感激。 I am using the python requests library 我正在使用python 请求库

commandPath = "Command.wav"
#Headers for http request
headers = {"authorization": "Bearer " + TOKEN,
    "Content-Type": "audio/wav",
    "Transfer-encoding": "chunked"}

#open Audio file to send
audioFile = open(commandPath, "rb")

def gen():
    #Keep getting audio until it has all been read
    while audioFile.read(2048) != "":
        yield audioFile.read(2048)
    print("Finished")


r = requests.post(ENDPOINT, headers=headers, data=gen())
print(r.text)

I guess the problem is that you are calling audioFile.read(2048) twice per loop, ignoring (and discarding) the result of the first call. 我想问题是每个循环您两次调用audioFile.read(2048) ,而忽略(并丢弃)第一次调用的结果。

The very first chunk (which you discard) holds the header information, which therefore never reaches the server, who rightfully complains. 第一个块(您丢弃的块)保存标头信息,因此该信息永远不会到达服务器,服务器会正​​确地进行抱怨。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM