首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >谷歌云语音文本AP

谷歌云语音文本AP
EN

Stack Overflow用户
提问于 2018-05-27 17:11:27
回答 1查看 240关注 0票数 1

我正在使用,并试图转录长音频file.However,无法检测到桶中的音频文件。我收到一个错误声明: error : Errno 2,没有这样的文件或目录:

def transcribe_gcs(gcs_uri):

代码语言:javascript
复制
time(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=16000,
    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))
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-06-28 07:26:56

尝尝这个

代码语言:javascript
复制
import requests
import json

url = "https://speech.googleapis.com/v1/speech:longrunningrecognize?key=<apiaccesskey>"


payload = {"config": {"encoding": "LINEAR16","sample_rate_hertz": 8000,
                     "language_code": "en-IN"},
                     "audio": {"uri": "gs://bucketname/file.flac"}}

r = requests.post(url, data=json.dumps(payload))

json_resp = r.json()
token_resp=json_resp['name']

url = "https://speech.googleapis.com/v1/operations/" + str(token_resp) + 
      "?key=<apiacesskey>"

content_response = requests.get(url)
content_json = content_response.json()

您的响应在content_json变量中。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50554575

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档