Warm tip: This article is reproduced from serverfault.com, please click

gcloud-将Google语音设置为Google Cloud上的文本

(gcloud - Setting up google speech to text on google cloud)

发布于 2020-11-30 22:36:16

我已经按照一堆关于Google文本语音的教程进行了学习,并使其在本地都能正常工作。我的设置是使用websockets(socket.io)在客户端Angular应用与对语音API进行服务器端调用的节点/表达式后端之间进行通信。我正在使用streaming-recognizehttps://cloud.google.com/speech-to-text/docs/streaming-recognize)读取麦克风流并返回结果。

这在本地完全可以运行,但是在gcloud app deploy实例上运行它时遇到了一个问题,因为我实际上没有安装SoX依赖项(通过本地完成brew install sox。这是他们设置麦克风流的示例的要求。

我想我需要设置一个可以使用SoX进行配置的虚拟机实例,但是我觉得这似乎有些过头了-有替代方法吗?我确实尝试手动解析并以Uint8Array / ArrayBuffer chunkns的形式发送麦克风数据流,但取得了一些成功,但效果并不理想。我还阅读了一些关于非SoX方法来处理用户麦克风流的假设,但毫无用处。例如带有recordrtc。

问题是-我需要怎么做才能在gcloud中工作?设置一个vm实例,安装sox,然后使用它?还是有没有SoX的方式来运行它?指导欢迎!

这是我在gcloud上遇到的服务器错误-在我看来,因为它的路径上没有SoX:

Error: spawn sox ENOENT      at Process.ChildProcess._handle.onexit (internal/child_process.js:267:19)      at onErrorNT (internal/child_process.js:469:16)      at processTicksAndRejections (internal/process/task_queues.js:84:21)
  Emitted 'error' event on ChildProcess instance at:
      at Process.ChildProcess._handle.onexit (internal/child_process.js:273:12)
      at onErrorNT (internal/child_process.js:469:16)
      at processTicksAndRejections (internal/process/task_queues.js:84:21) {
    errno: 'ENOENT',
    code: 'ENOENT',
    syscall: 'spawn sox',
    path: 'sox',
    spawnargs: [
      '--default-device',
      '--no-show-progress',
      '--rate',
      16000,
      '--channels',
      1,
      '--encoding',
      'signed-integer',
      '--bits',
      '16',
      '--type',
      'wav',
      '-'
    ]
  }
  npm ERR! code ELIFECYCLE
  npm ERR! errno 1
  npm ERR! <APPNAME>@0.0.0 start:prod: `node server.js;`
  npm ERR! Exit status 1
  npm ERR!
  npm ERR! Failed at the <APPNAME>@0.0.0 start:prod script.
  npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

  npm ERR! A complete log of this run can be found in:
  npm ERR!     /root/.npm/_logs/2020-11-30T22_12_35_041Z-debug.log
  npm ERR! code ELIFECYCLE
  npm ERR! errno 1
  npm ERR! <APPNAME>@0.0.0 start: `npm run start:prod`
  npm ERR! Exit status 1
  npm ERR!
  npm ERR! Failed at the <APPNAME>@0.0.0 start script.
  npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

  npm ERR! A complete log of this run can be found in:
  npm ERR!     /root/.npm/_logs/2020-11-30T22_12_35_074Z-debug.log
Questioner
bionara
Viewed
0
Nibrass H 2020-12-02 03:54:59

你正在尝试设置Google Speech to Text,并且要将其部署到Google App Engine(gcloud app deploy)上。

但是,Google Speech to Text具有Sox依赖性,因此需要在操作系统中安装Sox CLI。

因此,你将需要在自定义运行时中使用App Engine Flexible环境。在Dockerfile中,你可以指定安装SOX CLI。

通过快速入门中提供的步骤以及nodejs-speech存储库中的示例代码,我能够成功部署一个使用Speech to Text API的App Engine Flex应用程序请看看。

************** 更新 **************

Dockerfile:

FROM gcr.io/google-appengine/nodejs

# Working directory is where files are stored, npm is installed, and the application is launched
WORKDIR /app

# Copy application to the /app directory.
# Add only the package.json before running 'npm install' so 'npm install' is not run if there are only code changes, no package changes
COPY package.json /app/package.json
RUN apt-get update
RUN  apt-get install -y sox
RUN npm install
COPY . /app

# Expose port so when the container is launched you can curl/see it.
EXPOSE 8080

# The command to execute when Docker image launches.
CMD ["npm", "start"]

请尝试上面的Dockerfile并使其适应你的需求,这是如何安装sox的示例。