meteor - 如何将 Google Cloud Text-to-Speech 与 Meteor 集成
问题描述
我正在尝试在 Meteor 应用程序中使用 Google Cloud Text-to-Speech API,但在尝试使用说明中描述的导入功能时,在 Meteor 控制台上出现错误并崩溃:
("Uncaught TypeError: Cannot convert undefined or null to object at Function.getPrototypeOf (<anonymous>)")
这是我在启动流星之前所做的(在 app 目录中):
流星 npm 安装 google-tts-api
导出 GOOGLE_APPLICATION_CREDENTIALS="/data/authenticationinfo.json"
问题与在我的 js 文件顶部包含此行有关:
import textToSpeech from '@google-cloud/text-to-speech';
此行导致控制台上出现以下 Meteor 启动错误:“无法解析某些模块:/app/node_modules/@grpc/grpc-js/build/src/channel.js (web.browser) 中的“http2”
If you notice problems related to these missing modules, consider running:
meteor npm install --save meteor-node-stubs
实际上,我运行了上面的命令,但它没有效果。当我运行启动应用程序时,它会迅速崩溃并出现错误:
(未捕获的类型错误:无法将未定义或 null 转换为位于 module.exports 的 Function.getPrototypeOf () 处的对象(modules.js?hash=59a3378abff937a73bf3a9865d654fce71b9583a:91277)在 index.js (modules.js?hash=59a3378abff937a73bf3a99865d65869911b file: -runtime.js?hash=b819d45cbf32aff410d740fac0364cb4088cd3f2:346) at Module.require (modules-runtime.js?hash=b819d45cbf32aff410d740fac0364cb4088cd3f2:248) at require (modules-runtime.js?hash=b819d45cbf32aff410d740fac0364cb4088cd3f2:268) at jwtclient.js (modules. js?hash=59a3378abff937a73bf3a9865d654fce71b9583a:79821) at fileEvaluate (modules-runtime.js?hash=b819d45cbf32aff410d740fac0364cb4088cd3f2:346) at Module.require (modules-runtime.js?hash=b819d45cbf32aff410d740fac0364cb4088cd3f2:248) at require (modules-runtime.js?hash=b819d45cbf32aff410d740fac0364cb4088cd3f2:268)
我已经在准系统节点应用程序上对其进行了测试,并且我的 Google 身份验证 json 文件工作正常,所以这绝对不是问题。
我知道有一些谷歌 TTS 的 Meteor 包,但它们真的很旧,并且使用谷歌翻译(它不会长时间工作)而不是新的云服务。
解决方案
因此,事实证明导入必须发生在服务器端,而不是客户端。
推荐阅读
- html - Svg 动画在移动 safari 中有混蛋
- css - 向下滚动时需要将引导导航栏固定为固定
- vba - 使用 VBA 选择最后一个值以指定 Excel 瀑布图中的总计
- ios - 我想使用 Alamofire swift 4 发布对象数组
- java - 如何打印数组索引号?
- ios - 无法将数据保存到 MVC (Swift)
- ruby-on-rails - 将下拉标签、下拉和提交按钮放在同一行
- swift - 按下后退按钮后,从另一个视图控制器更改按钮
- angular5 - *ngFor 中的选择、取消选择、中间复选框树视图
- javascript - 使用 php 和 javascript 的价格范围