我正在尝试使用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云端存储中?
答案 0 :(得分:1)
我注意到gcs_uri实际上应该引用Google云中的目录。格式应类似于gs://<bucket_name>/<file_path_inside_bucket>
答案 1 :(得分:0)
还有很多长文件友好的ASR API