【问题标题】:Transcribing Long Audio File doesn't work转录长音频文件不起作用
【发布时间】: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 云存储的情况下转录大型音频文件?

【问题讨论】:

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


【解决方案1】:

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

【讨论】:

    【解决方案2】:

    还有很多对长文件友好的 ASR API

    【讨论】:

    • 你能举几个例子吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-03
    • 1970-01-01
    • 1970-01-01
    • 2014-05-27
    • 1970-01-01
    相关资源
    最近更新 更多