[英]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.