如何从Google Apps脚本授权Google语音转文本? [英] How can I authorize Google Speech-to-text from Google Apps script?

查看:128
本文介绍了如何从Google Apps脚本授权Google语音转文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从应用脚本执行google-speech-to-text.不幸的是,我找不到适用于应用程序脚本或纯HTTP的任何示例,因此可以使用简单的UrlFetchApp运行它.

I'm trying to execute google-speech-to-text from apps script. Unfortunately, I cannot find any examples for apps script or pure HTTP, so I can run it using simple UrlFetchApp.

我创建了一个服务帐户,并设置了启用了语音到文本api的项目,并且能够 使用命令行示例成功运行识别

I created a service account and setup a project with enabled speech-to-text api, and was able to successfully run recognition using command-line example

curl -s -H内容类型:application/json" \ -H授权:承载" $(gcloud auth application-default print-access-token)\ https://speech.googleapis.com/v1/speech:recognize \ -d @ sync-request.json

curl -s -H "Content-Type: application/json" \ -H "Authorization: Bearer "$(gcloud auth application-default print-access-token) \ https://speech.googleapis.com/v1/speech:recognize \ -d @sync-request.json

我可以轻松地将其转换为UrlFetchApp调用,但是我不知道如何生成由创建的访问令牌

which I can easily translate to UrlFetchApp call, but I don't have an idea to generate access token created by

gcloud auth应用程序-默认打印访问令牌

gcloud auth application-default print-access-token

是否可以使用服务帐户凭据从应用程序脚本中获取它?

Is there a way to get it from apps script using service account credentials?

或者还有其他方法可以通过应用脚本进行身份验证和访问语音转文本吗?

Or is there any other way to auth and access speech-to-text from apps script?

推荐答案

通过服务帐户检索访问令牌的等效方法是通过

The equivalent of retrieving access tokens through service accounts is through the apps script oauth library. The library handles creation of the JWT token.

示例此处

这篇关于如何从Google Apps脚本授权Google语音转文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆