首页 > 解决方案 > 如何将 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 目录中):

  1. 流星 npm 安装 google-tts-api

  2. 导出 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 包,但它们真的很旧,并且使用谷歌翻译(它不会长时间工作)而不是新的云服务。

标签: meteorgoogle-cloud-platformtext-to-speech

解决方案


因此,事实证明导入必须发生在服务器端,而不是客户端。


推荐阅读