gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 08:54:49 33 4
gpt4 key购买 nike

我正在尝试使用 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/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com