Преобразование речи в текст Google зависает при response = client.recognize(config audio)

У меня проблема, и я не знаю, что делать. Я хочу расшифровать аудиофайл с помощью преобразования речи Google в текст. Когда я выполняю скрипт python, все в порядке, но код зависает на "Response = Client.recognize(config, audio)". Сообщение об ошибке отсутствует. Когда я прерываю сценарий, я вижу, что код der зависает в time.sleep. Странно, что следы питонаtypes.RecognitionAudio(Content=concent) а также types.Recognitionconfigкрасным цветом с примечанием. Модуль "Google.cloud.speech_v1.types" не имеет элемента "RecognitionAudio" / "RecognitionConfig". Но консоль не выдает ошибку о "типах", отмеченных красным.

Кто-нибудь знает, что я делаю не так? Буду очень рад получить поддержку.

Код:

import io
import os

# Imports the Google Cloud client library
from google.cloud import speech
from google.cloud.speech import enums
from google.cloud.speech import types
from google.oauth2 import service_account
#from google.cloud import speech_v1

os.environ['GOOGLE_APPLICATION_CREDENTIALS'] = "./path/Key.json"
creds = service_account.Credentials.from_service_account_file('./path/Key.json')
print('Credentials from environ: {}'.format(os.environ.get('GOOGLE_APPLICATION_CREDENTIALS'))) 


# Instantiates a client
client = speech.SpeechClient()

# The name of the audio file to transcribe
file_name = os.path.join(
    os.path.dirname(__file__),
    'resources',
    'test.wav')

# Loads the audio into memory
with io.open(file_name, 'rb') as audio_file:
    content = audio_file.read()
    audio = types.RecognitionAudio(content=content)

config = types.RecognitionConfig(
    encoding=enums.RecognitionConfig.AudioEncoding.LINEAR16,
    sample_rate_hertz=16000,
    language_code='de-DE')

# Detects speech in the audio file
response = client.recognize(config, audio)
#response = client.recognize(config, audio)

for result in response.results:
    print('Transcript: {}'.format(result.alternatives[0].transcript))

Консоль:

PS C:\Users\Twilio-Test> & C:/Users/Twilio-Test/AppData/Local/Programs/Python/Python38/python.exe c:/Users/Twilio-Test/Desktop/temp.py
Credentials from environ: ./path/Key.json
Traceback (most recent call last):
  File "c:/Users/Twilio-Test/Desktop/temp.py", line 36, in <module>
    response = client.recognize(config, audio)
  File "C:\Users\Twilio-Test\AppData\Local\Programs\Python\Python38\lib\site-packages\google\cloud\speech_v1\gapic\speech_client.py", line 255, in recognize
    return self._inner_api_calls["recognize"](
  File "C:\Users\Twilio-Test\AppData\Local\Programs\Python\Python38\lib\site-packages\google\api_core\gapic_v1\method.py", line 143, in __call__
    return wrapped_func(*args, **kwargs)
  File "C:\Users\Twilio-Test\AppData\Local\Programs\Python\Python38\lib\site-packages\google\api_core\retry.py", line 281, in retry_wrapped_func
    return retry_target(
  File "C:\Users\Twilio-Test\AppData\Local\Programs\Python\Python38\lib\site-packages\google\api_core\retry.py", line 215, in retry_target
    time.sleep(sleep)
KeyboardInterrupt

0 ответов

Другие вопросы по тегам