【发布时间】:2018-10-23 07:24:53
【问题描述】:
我正在尝试使用来自 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 云存储的情况下转录大型音频文件?
【问题讨论】:
-
参考here。
标签: python google-api speech-recognition speech-to-text