【发布时间】:2013-11-23 07:37:02
【问题描述】:
我正在尝试在 Python 中使用 Google Speech API。我像这样加载一个 .flac 文件:
url = "https://www.google.com/speech-api/v1/recognize?xjerr=1&client=chromium&lang=en-US"
audio = open('temp_voice.flac','rb').read()
headers = {'Content-Type': 'audio/x-flac; rate=44100', 'User-Agent':'Mozilla/5.0'}
req = urllib2.Request(url, data=audio, headers=headers)
resp = urllib2.urlopen(req)
system("rm temp_voice.wav; rm temp_voice.flac")
print resp.read()
输出:
{"status":0,"id":"","hypotheses":[{"utterance":"今天是星期三","confidence":0.75135982}]}
谁能教我如何提取文本“今天是星期三”并将其保存为变量并打印?
【问题讨论】:
-
用
jsonmodule怎么样?
标签: python json google-api