我一直在尝试开发一个 python 脚本来从嘈杂的音频文件中转录音频。我的具体用例是正确转录嘈杂的音频部分。当我将文件发送到 SpeechML API 进行处理时,对于嘈杂的音频,响应要么省略要么不正确。有没有办法解决这个问题?我已经尝试过一些工具,比如 sox、语音识别包装器,但它们没有帮助下面是我正在使用的代码
def transcribe_gcs(gcs_uri):
"""Asynchronously transcribes the audio file specified by the gcs_uri."""
from google.cloud import speech
from google.cloud.speech import enums
from google.cloud.speech import types
client = speech.SpeechClient()
audio = types.RecognitionAudio(uri=gcs_uri)
config = types.RecognitionConfig(
encoding=enums.RecognitionConfig.AudioEncoding.FLAC,
sample_rate_hertz=48000,
language_code='en-US')
operation = client.long_running_recognize(config, audio)
print('Waiting for operation to complete...')
response = operation.result(timeout=600)
# 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('Transcript: {}'.format(result.alternatives[0].transcript))
print('Confidence: {}'.format(result.alternatives[0].confidence))
# [END def_transcribe_gcs]
如果名称== '主要':
gcs_uri="gs://speechmldemo/outputclear.flac"
transcribe_gcs(gcs_uri)