繁体   English   中英

设置wit.ai语音API的录制时间

[英]Set recording time for wit.ai speech API

我一直在使用python 3.7.3中的语音识别。 作为一个基础,我使用了Wit.ai的示例代码,我已经在线了。 我的问题是,我无法增加重新编码时间。 默认情况下为4秒。 当我将其更改为10秒或更长时,我得到以下错误

回溯(最近一次调用最后一次):文件“C:/ Users / xyx / Downloads / Desktop / python STT / main.py”,第41行,文本= RecognizeSpeech('myspeech.wav',15)文件“C:/ Users / xyx / Downloads / Desktop / python STT / main.py“,第34行,在RecognizeSpeech text = data ['_ text'] KeyError:'_ text'

感谢任何帮助。 谢谢。

我的python代码如下: -

import requests
import json
from Recorder import record_audio, read_audio

# Wit speech API endpoint
API_ENDPOINT = 'https://api.wit.ai/speech'

# Wit.ai api access token
wit_access_token = 'MY WIT.AI KEY'


def RecognizeSpeech(AUDIO_FILENAME, num_seconds = 5):

    # record audio of specified length in specified audio file
    record_audio(num_seconds, AUDIO_FILENAME)

    # reading audio
    audio = read_audio(AUDIO_FILENAME)

    # defining headers for HTTP request
    headers = {'authorization': 'Bearer ' + wit_access_token,
               'Content-Type': 'audio/wav'}

    # making an HTTP post request
    resp = requests.post(API_ENDPOINT, headers = headers,
                         data = audio)

    # converting response content to JSON format
    data = json.loads(resp.content)

    # get text from data
    text = data['_text']

    # return the text
    return text

if __name__ == "__main__":
    text =  RecognizeSpeech('myspeech.wav', 15)
    print("\nYou said: {}".format(text))

这是wit.ai API的限制。 使用与谷歌不同的API,他们有一个很好的流媒体版本,提供快速响应,可以处理更长的输入。

暂无
暂无

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

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