【发布时间】:2019-03-19 21:42:03
【问题描述】:
我正在尝试在以下 Python 程序中使用 IBM Watson 语音转文本 API/服务。
import json
import os
import sys
from watson_developer_cloud import SpeechToTextV1
def transcribe_audio(audio_file_name) :
IBM_USERNAME = "yourusername"
IBM_PASSWORD = "yourpassword"
#what changes should be made here instead of username and password
stt = SpeechToTextV1(username=IBM_USERNAME, password=IBM_PASSWORD)
audio_file = open(audio_file_name, "rb")
json_file = os.path.abspath("america")+".json";
with open(json_file, 'w') as fp:
result = stt.recognize(audio_file,timestamps=True,content_type='audio/wav', inactivity_timeout =-1,word_confidence = True)
result.get_result()
json.dump(result, fp, indent=2)
script = "Script is : "
for rows in result['results']:
script += rows['alternatives'][0]['transcript']
print(script)
transcribe_audio("america.wav")
这段代码给了我标题中提到的身份验证错误,因为 IBM 将授权方法从 username + password 更改为 apikey 最近。
谁能告诉我应该对此进行哪些更改? 以及如何在 IBM Watson 语音上生成 apikey 到带有用户名和密码的文本?
我是语音识别的新手,请告诉我。提前致谢。
【问题讨论】:
-
如何将 ibm watson 语音上的 api 密钥生成为带有用户名和密码的文本? 你会自动得到 spikey 。检查您的IBM Cloud console 并单击您的服务。但此 apikey 不用于流式音频的身份验证。
-
请通过this documentation。直接跳过 SDK 可能不是一个好主意。
-
@RC0993 非常感谢。我在发布后不久就想出了获取 api 密钥。
-
@RC0993 但是你提到的文档链接非常有用,节省了很多时间。
-
你能解决这个问题吗,如果是,你能在这里发布答案,这对我有很大的帮助,因为我面临同样的问题。
标签: python-3.x speech-recognition ibm-watson speech-to-text