[英]Getting a google api client error using the Uberi speech to text code
I am trying to use Uberi's speech to text code with the google cloud platform (GCP) speech to text API. 我正在尝试将Uberi的语音文本与Google云平台(GCP)语音文本API结合使用。 I am getting the following error:
googleapiclient.errors.UnknownApiNameOrVersion: name: speech version: v1beta1
我收到以下错误:
googleapiclient.errors.UnknownApiNameOrVersion: name: speech version: v1beta1
Anyone know how to fix this error? 有人知道如何解决此错误吗? Cant seem to find anything on Uberi github page.
无法在Uberi github页面上找到任何内容。 Was wondering if anyone has come across a similar error using the GCP or if anyone has a better way of embedding the google API speech-to-text code that works.
想知道是否有人使用GCP遇到类似错误,或者是否有人有更好的方法嵌入有效的google API语音转文本代码。
The GCP documentation isn't very clear! GCP文档不是很清楚!
I am using the following code: 我正在使用以下代码:
recognizer = sr.Recognizer()
pa = pyaudio.PyAudio()
audio_rate = args.rate
stream_buf = bytes()
stream_counter = 0
def recognize(stream_text):
global args
def logger(s):
f = open('recognition_log2.txt', 'a+', encoding='utf-8')
f.write(datetime.datetime.now().strftime("[ %d-%b-%Y %H:%M:%S ] "))
f.write(s)
f.write("\x0A")
f.close()
audio_data = sr.AudioData(stream_text, audio_rate, 2)
GOOGLE_CLOUD_SPEECH_CREDENTIALS = r"""{
"type": "service_account",
"project_id": "xxx",
"private_key_id": "xxx",
"private_key": "xxx",
"client_email": "xxx",
"client_id": "xxx",
"auth_uri": "xxx",
"token_uri": "xxx",
}
"""
try:
result = recognizer.recognize_google_cloud(audio_data, credentials_json=GOOGLE_CLOUD_SPEECH_CREDENTIALS)
print(result)
logger(result)
except sr.UnknownValueError:
pass
except sr.RequestError as e:
print("Could not request results from GSR service; {0}".format(e))
def stream_audio(data):
global args
global stream_buf
global stream_counter
if stream_counter < args.buf:
stream_buf += data
stream_counter += 1
else:
threading.Thread(target=recognize, args=(stream_buf,)).start()
stream_buf = bytes()
stream_counter = 0
def callback(in_data, frame_count, time_info, status):
stream_audio(in_data)
return (None, pyaudio.paContinue)
stream = pa.open(format=pyaudio.paInt16, channels=1, rate=audio_rate, input=True, stream_callback=callback,
input_device_index=args.device)
stream.start_stream()
while stream.is_active(): time.sleep(0.1)
stream.stop_stream()
stream.close()
pa.terminate()
Figured out what the issue was, managed to read through a bunch of reported issues on Uberi's github page. 找出问题所在,设法阅读了Uberi github页面上的一系列报告问题。
Simple solution was to just update the package to 3.8, I was running 3.6 which was using the old google cloud service. 一个简单的解决方案是将软件包更新为3.8,我正在运行3.6,该版本使用的是旧版Google云服务。
Thanks Dustin! 谢谢达斯汀!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.