python - 转录长音频文件不起作用

标签 python google-api speech-recognition speech-to-text

我正在尝试使用 google page 中的示例代码转录 30 分钟的 .wav 文件。我对原始代码做了一些更改,如下:

from google.cloud import speech
from google.cloud.speech import enums
from google.cloud.speech import types

os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = 'C:\\Users\\louie\\Desktop\\PSC.json'
gcs_uri = os.path.join('C:\\Users\\louie\\Desktop','Untitled1.wav')

client = speech.SpeechClient()

audio = types.RecognitionAudio(uri=gcs_uri)
config = types.RecognitionConfig(
    encoding=enums.RecognitionConfig.AudioEncoding.LINEAR16,
    sample_rate_hertz=44100,
    language_code='en-US')

operation = client.long_running_recognize(config, audio)

print('Waiting for operation to complete...')
response = operation.result(timeout=90)

# Each result is for a consecutive portion of the audio. Iterate through
# them to get the transcripts for the entire audio file.
for result in response.results:
    # The first alternative is the most likely one for this portion.
    print(u'Transcript: {}'.format(result.alternatives[0].transcript))
    print('Confidence: {}'.format(result.alternatives[0].confidence))

当我运行它时,我收到错误400 Request contains an invalid argument我很确定我的预设是正确的,因为短转录的代码适合我。有人可以帮我解决这个问题吗?谢谢!

编辑:我认为这个问题与 gcs_uri 格式错误有关。有没有办法转录大型音频文件而不将其上传到 Google 云存储?

最佳答案

我注意到 gcs_uri 实际上应该引用 Google 云中的目录。格式应类似于 gs://<bucket_name>/<file_path_inside_bucket>

关于python - 转录长音频文件不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52847396/

相关文章:

python - Azure 发音评估 SDK 与 api 调用相比返回错误结果

python-3.x - 我会选择什么设备进行语音识别以使用来自计算机的音频?

python - Django从外键类中获取属性

iphone - 是否可以直接在 google plus 上发布而无需在网络上添加其他共享对话框

python - 如何在满足特定的 "for loop"条件时跳过一轮 "if"继续下一轮?

node.js - 谷歌健身 : API gets only details of datasources but not the details of calories in nodejs

java - Google Drive API 401 未经授权错误

java - 一起运行 Pocketsphinx 和 Google TTS

python - Pandas : reshape 数据

python - tensorflow.python.framework.errors_impl.InvalidArgumentError : Invalid argument: assertion failed: