Loading [MathJax]/jax/output/CommonHTML/config.js
首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
社区首页 >问答首页 >如何将音频文件从S3桶直接传送到Google语音到文本

如何将音频文件从S3桶直接传送到Google语音到文本
EN

Stack Overflow用户
提问于 2020-12-23 02:38:37
回答 1查看 526关注 0票数 3

我们正在使用Google的语音到文本API开发一个语音应用程序。现在,我们的数据(音频文件)存储在AWS上的S3桶中。有办法直接将S3 URI传递给Google的语音到文本API吗?

从他们的文档来看,在Google的语音到文本API中,这在目前看来是不可能的。

对于他们的愿景和NLP API来说,情况并非如此。

  1. 你知道为什么对语音API有这样的限制吗?
  2. 这里有什么好工作要做?
EN

回答 1

Stack Overflow用户

发布于 2021-01-07 00:23:17

目前,谷歌的只允许音频文件从您的本地来源或谷歌的云存储。对这方面的文件没有给予合理的解释。

传递由URI引用的音频更典型地,您将在语音请求的音频字段中传递一个uri参数,指向位于Google上的音频文件(二进制格式,而不是base64)

我建议你把你的文件移到。如果您不愿意,有一个很好的解决办法:将与流API结合使用。你不需要在任何地方储存任何东西。您的语音应用程序提供来自任何麦克风的输入。如果你不知道如何处理来自麦克风的输入,那就别担心。

谷歌提供了一个样本代码来完成这一切:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
# [START speech_transcribe_streaming_mic]
from __future__ import division

import re
import sys

from google.cloud import speech

import pyaudio
from six.moves import queue

# Audio recording parameters
RATE = 16000
CHUNK = int(RATE / 10)  # 100ms


class MicrophoneStream(object):
    """Opens a recording stream as a generator yielding the audio chunks."""

    def __init__(self, rate, chunk):
        self._rate = rate
        self._chunk = chunk

        # Create a thread-safe buffer of audio data
        self._buff = queue.Queue()
        self.closed = True

    def __enter__(self):
        self._audio_interface = pyaudio.PyAudio()
        self._audio_stream = self._audio_interface.open(
            format=pyaudio.paInt16,
            channels=1,
            rate=self._rate,
            input=True,
            frames_per_buffer=self._chunk,
            # Run the audio stream asynchronously to fill the buffer object.
            # This is necessary so that the input device's buffer doesn't
            # overflow while the calling thread makes network requests, etc.
            stream_callback=self._fill_buffer,
        )

        self.closed = False

        return self

    def __exit__(self, type, value, traceback):
        self._audio_stream.stop_stream()
        self._audio_stream.close()
        self.closed = True
        # Signal the generator to terminate so that the client's
        # streaming_recognize method will not block the process termination.
        self._buff.put(None)
        self._audio_interface.terminate()

    def _fill_buffer(self, in_data, frame_count, time_info, status_flags):
        """Continuously collect data from the audio stream, into the buffer."""
        self._buff.put(in_data)
        return None, pyaudio.paContinue

    def generator(self):
        while not self.closed:
            # Use a blocking get() to ensure there's at least one chunk of
            # data, and stop iteration if the chunk is None, indicating the
            # end of the audio stream.
            chunk = self._buff.get()
            if chunk is None:
                return
            data = [chunk]

            # Now consume whatever other data's still buffered.
            while True:
                try:
                    chunk = self._buff.get(block=False)
                    if chunk is None:
                        return
                    data.append(chunk)
                except queue.Empty:
                    break

            yield b"".join(data)


def listen_print_loop(responses):
    """Iterates through server responses and prints them.
    The responses passed is a generator that will block until a response
    is provided by the server.
    Each response may contain multiple results, and each result may contain
    multiple alternatives; for details, see the documentation.  Here we
    print only the transcription for the top alternative of the top result.
    In this case, responses are provided for interim results as well. If the
    response is an interim one, print a line feed at the end of it, to allow
    the next result to overwrite it, until the response is a final one. For the
    final one, print a newline to preserve the finalized transcription.
    """
    num_chars_printed = 0
    for response in responses:
        if not response.results:
            continue

        # The `results` list is consecutive. For streaming, we only care about
        # the first result being considered, since once it's `is_final`, it
        # moves on to considering the next utterance.
        result = response.results[0]
        if not result.alternatives:
            continue

        # Display the transcription of the top alternative.
        transcript = result.alternatives[0].transcript

        # Display interim results, but with a carriage return at the end of the
        # line, so subsequent lines will overwrite them.
        #
        # If the previous result was longer than this one, we need to print
        # some extra spaces to overwrite the previous result
        overwrite_chars = " " * (num_chars_printed - len(transcript))

        if not result.is_final:
            sys.stdout.write(transcript + overwrite_chars + "\r")
            sys.stdout.flush()

            num_chars_printed = len(transcript)

        else:
            print(transcript + overwrite_chars)

            # Exit recognition if any of the transcribed phrases could be
            # one of our keywords.
            if re.search(r"\b(exit|quit)\b", transcript, re.I):
                print("Exiting..")
                break

            num_chars_printed = 0


def main():
    language_code = "en-US"  # a BCP-47 language tag

    client = speech.SpeechClient()
    config = speech.RecognitionConfig(
        encoding=speech.RecognitionConfig.AudioEncoding.LINEAR16,
        sample_rate_hertz=RATE,
        language_code=language_code,
    )

    streaming_config = speech.StreamingRecognitionConfig(
        config=config, interim_results=True
    )

    with MicrophoneStream(RATE, CHUNK) as stream:
        audio_generator = stream.generator()
        requests = (
            speech.StreamingRecognizeRequest(audio_content=content)
            for content in audio_generator
        )

        responses = client.streaming_recognize(streaming_config, requests)

        # Now, put the transcription responses to use.
        listen_print_loop(responses)


if __name__ == "__main__":
    main()
# [END speech_transcribe_streaming_mic]

依赖关系是google-cloud-speechpyaudio

对于AWS S3,您可以在从Google获得记录稿之前/之后将您的音频文件存储在那里。流也是超快的。

别忘了附上你的证件。您需要首先通过提供GOOGLE_APPLICATION_CREDENTIALS获得授权

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

https://stackoverflow.com/questions/65422902

复制
相关文章
HTTP协议中的401授权认证机制在iOS上的实现
我们在用NSURLConnection或者NSURLSession进行HTTP请求时,有些URL因为需要授权认证而返回401,因此客户端需要在HTTP的请求头中带上用户和密码进行授权认证(具体查看这里);或者当我们使用HTTPS协议时,一旦服务器提供的证书不被默认信任则需要客户端人为确认是否信任此服务器证书;或者用HTTPS协议时服务端也需要客户端提供证书进行双向认证时;或者我们是通过代理服务器来请求数据时客户端需要提供代理服务器的用户和密码进行认证。我们称这些情况为服务端要求客户端接收认证挑战(AuthenticationChallenge)。
欧阳大哥2013
2018/08/22
1.3K0
【分享】在集简云上架应用使用API授权如何配置?
授权字段为用户在前端授权时要求填写的字段,例如API Key,设置后,用户在集简云平台使用我们的应用时,点击“添加账户”弹窗窗口中填写,例如如果我们设置了一个"API Key"字段,那么用户使用时点击添加账户就会要求其填写自己的 API Key:
集简云
2022/08/19
9000
SpringBoot Security 访问API始终报401
用POSTMAN或者在页面前端登录访问后端API时,始终返回401.返回401有很多原因造成的,主要分为两个方面来看:
芥末鱿鱼
2022/05/05
3.3K0
微服务与API 网关(上): 为什么需要API网关?
本文是来自于Macro在一次大会上的一个分享。 本系列共有两个部分,主要关注我们如何以及为什么要在我们的微服务应用中部署API 网关。第二部分主要关注我们如何把Mashape的开源网关组件Kong运用到我们自己的微服务架构当中。 目录 0:00 微服务与网关(Microservices & API Gateways) 大家好,我叫Macro,今天我们谈论有关微服务和网关的话题。我是Mashape的CTO,也同时是开源网关Kong的开发者之一。Kong是一个API网关,今天我们就来窥探一下它究竟是
ImportSource
2018/04/03
2.6K0
微服务与API 网关(上): 为什么需要API网关?
安卓请求文件授权
我将于茫茫人海中访我唯一灵魂之伴侣;得之,我幸;不得,我命,如此而已。——徐志摩 安卓请求文件授权 在AndroidManifest.xml中加上 <!-- 往SDCard写入数据权限 --> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <!-- 从SDCard读入数据权限 --> <uses-permission android:name="android.permission.READ_E
阿超
2022/08/16
8130
安卓请求文件授权
Laravel Sanctum API 授权
简单来说,前后端分离的项目,使用 token 验证登陆状态,可以选它;另外,同类型的还有 jwt 比较火
崔哥
2023/04/16
3.1K0
在以太坊上构建 GraphQL API
dapp[5]的数量继续爆炸性增长,对开发人员(使用 Solidity[6]或其他区块链语言的)的需求[7]也越来越大。
Tiny熊
2021/06/10
1.8K0
在以太坊上构建 GraphQL API
在restful api模式上使用JWT
在header头里面增加Authorization。在服务端验证的时候回通过取得这个值来验证回话的有效。
友儿
2022/09/11
8390
vue在headers中带入token:解决401
js export function 函数名(params) { return axios({ url: api.函数名, data: params, params: params, headers: { 'Authorization': 'Bearer ' + params.token } }) } 单页面 函数名: function () { let token = Vu
江一铭
2022/06/16
7790
JAVA接入淘宝授权API
如果您的应用和淘宝开放平台对接后,需要获取用户隐私信息(如:商品、订单、收藏夹等),为保证用户数据的安全性与隐私性,您的应用需要取得用户的授权。在这种情况下,您的应用需要引导用户完成“使用淘宝帐号登录并授权”的流程。
凯哥Java
2019/06/28
3.7K0
JAVA接入京东授权API
如果您的应用已和京东JOS对接,需要获取一些与用户紧密相关的信息(如订单、商品、促销等),为保证数据的安全性和隐私性,需要取得用户的同意,引导用户授权。JOS采用国际通用的OAuth2.0标准协议,支持网站、桌面客户端、ERP系统。如果要了解更多关于OAuth2.0的技术说明,请参考官方网站  http://oauth.net/2/  。目前,JOS的OAuth2.0支持以下方式获取Access Token。
凯哥Java
2019/06/28
3.1K0
Google JS API 授权 失败
// 初始化OAuth2.0授权 const authenticate = () => { return gapi.auth2.getAuthInstance() .signIn({scope: "https://www.googleapis.com/auth/documents https://www.googleapis.com/auth/drive https://www.googleapis.com/auth/driv
拿我格子衫来
2022/01/24
4K0
Google JS API 授权 失败
Go 语言技术大佬们在 Twitter 上打起了口水战
转载链接:https://zhuanlan.zhihu.com/p/41627929
老钱
2018/12/14
1.1K0
Docker Daemon API未授权
Docker Remote API是一个取代远程命令行界面(RCLI)的REST API,当该接口直接暴漏在外网环境中且未作权限检查时,攻击者可以通过恶意调用相关的API实现远程命令执行
Al1ex
2022/09/07
9720
Docker Daemon API未授权
在 Mac 上安装 Git ,生成 SSH 密钥用于 GitHub 授权
我们需要的 SSH 公钥存储在以.pub结尾的文件中,即: ~/.ssh/id_rsa.pub
圆号本昊
2021/09/24
2.3K0
在 Mac 上安装 Git ,生成 SSH 密钥用于 GitHub 授权
API Gateway Kong在Rainbond上的部署
Kong是一个可扩展的开源API平台(也称为API网关,API中间件或微服务服务网格)。Kong最初是由Kong Inc.(以前称为Mashape)实现的,用于为其API Marketplace维护、管理和扩展超过15,000个微服务,这些微服务每月产生数十亿个请求。
Rainbond开源
2020/01/02
1.3K0
SAP JAVA 调用ABAP webservice 报错Transport error : 401Error:Unauthorized 授权失败
简介:   解决 webservice 调用之后报错:调用异常:Transport error : 401 Error:Unauthorized 授权失败。 加入如下代码 //Sap需要ws-security的认证,调用sap webservice的认证信息需要输入用户名和密码: HttpTransportProperties.
matinal
2023/10/13
3520
SAP JAVA 调用ABAP webservice 报错Transport error : 401Error:Unauthorized 授权失败
Node.js-具有示例API的基于角色的授权教程
1.从https://github.com/cornflourblue/node-role-based-authorization-api下载或克隆教程项目代码 2.通过从项目根文件夹(package.json所在的位置)中的命令行运行npm install来安装所有必需的npm软件包。 3.通过从项目根文件夹中的命令行运行npm start来启动api,您应该看到消息 Server listening on port 4000。您可以使用诸如Postman之类的应用程序直接测试api,也可以使用下面的单个页面的示例应用程序来测试它。
ccf19881030
2020/08/11
5.7K0
Docker API未授权命令执行
Docker Swarm是Docker的集群管理工具,它将Docker主机池转变为单个虚拟Docker主机,能够方便的进行docker集群的管理和扩展。Docker Swarm使用标准的Docker API通过2375端口来管理每个Docker节点,Docker API是一个取代远程命令行界面(RCLI)的REST API。当Docker节点的2375端口直接暴露并未做权限检查时,存在未授权访问漏洞,攻击者可以利用Docker API执行任何操作,包括执行Docker命令,创建、删除Docker以及获得宿主机权限等。
谢公子
2023/09/01
1.3K0
Docker API未授权命令执行
点击加载更多

相似问题

401:从Twitter API检索请求令牌时需要授权

10

Twitter Stream API - 401未经授权

32

需要AngularJs "401授权“的Vimeo API请求

20

Twitter授权/签名的get请求返回401未授权

10

Twitter401未授权-- OAuth请求令牌

14
添加站长 进交流群

领取专属 10元无门槛券

AI混元助手 在线答疑

扫码加入开发者社群
关注 腾讯云开发者公众号

洞察 腾讯核心技术

剖析业界实践案例

扫码关注腾讯云开发者公众号
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档
查看详情【社区公告】 技术创作特训营有奖征文