Python 返回音频中的五个单词,持续时间为1分钟
我已经实现了谷歌的示例代码,将音频转换为文本,音频托管在谷歌云中,并具有以下功能:格式:flac,采样率:16000,320kbps,频道:mono,语言:西班牙语。我使用以下代码:Python 返回音频中的五个单词,持续时间为1分钟,python,google-cloud-speech,Python,Google Cloud Speech,我已经实现了谷歌的示例代码,将音频转换为文本,音频托管在谷歌云中,并具有以下功能:格式:flac,采样率:16000,320kbps,频道:mono,语言:西班牙语。我使用以下代码: import sys import os import io os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = '/home/eparionad/Dropbox/Tesis/CredencialesApiGoogle/Tesis-59cc7659afbc.json'
import sys
import os
import io
os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = '/home/eparionad/Dropbox/Tesis/CredencialesApiGoogle/Tesis-59cc7659afbc.json'
speech_file = '/home/eparionad/Descargas/19-02-2018/JuninInformado/3-JuninInformado-19-02-18-13:51.flac'
def transcribe_gcs():
"""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()
gcs_uri = 'gs://audiosparareconocimiento/3-JuninInformado-19-02-18-13:51.flac'
audio = types.RecognitionAudio(uri=gcs_uri)
config = types.RecognitionConfig(
encoding=enums.RecognitionConfig.AudioEncoding.FLAC,
sample_rate_hertz=16000,
language_code='es-PE')
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('Transcript: {}'.format(result.alternatives[0].transcript))
print('Confidence: {}'.format(result.alternatives[0].confidence))
# [END def_transcribe_gcs]
transcribe_gcs()
尝试增加超时值以获取更多单词 而不是:
response = operation.result(timeout=90)
付诸表决:
在这篇文章中,你没有问过任何问题。你的问题是什么?你能发布整个OperationID回复正文吗?{}. 这样你就可以确保它已经完成了操作。它必须有一个done=true标志。你到底在回答什么问题?因为标题上说音频只返回五个单词!!这个问题是含蓄的!请更改您的费率,然后让OP澄清。标题并不是只说。OP没有显示任何错误消息或输出。在任何地方都没有提出任何具体问题。好吧,我明白了。对不起,录音持续一分钟,是一个人讲故事的声音。更改为您建议的值,但只返回叙述的第一个单词,就好像您没有检测到任何叙述一样。
response = operation.result(timeout=900)