【问题标题】:Setting up google speech to text on google cloud - Error: spawn SoX ENOENT在谷歌云上设置谷歌语音到文本 - 错误:产生 SoX ENOENT
【发布时间】:2020-11-30 22:36:16
【问题描述】:

我已经学习了一堆关于 Google 语音转文本的教程,并且在本地都可以正常运行。我的设置是使用 websockets (socket.io) 在客户端 Angular 应用程序和对语音 API 进行服务器端调用的节点/快速后端之间进行通信。我正在使用streaming-recognize (https://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

【问题讨论】:

    标签: google-cloud-platform gcloud google-cloud-speech sox


    【解决方案1】:

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

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

    因此,您需要使用具有自定义运行时的 App Engine 柔性环境。在 Dockerfile 中,您可以指定安装 SOX CLI。

    使用quickstart 中提供的步骤和nodejs-speech repository 中的示例代码,我能够成功部署使用 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 的示例。

    【讨论】:

    • 非常感谢您的指导!看起来很有希望。我已经进行了一些研究,并尝试按照以下方式进行设置:github.com/GoogleCloudPlatform/… 我在启动它时遇到了一些困难 - 你有一个 Dockerfile 的示例,我可以使用它来让我的灵活环境运行,并安装 SoX?
    • 我更新了我的答案,请看一下。
    • 太棒了,谢谢!到目前为止,它已经对我遇到的所有错误进行了排序 - 现在出现了一个有点神秘的错误 sox has exited with error code 2. 。跟踪 gcloud app logs tail 时,在此之上或之下没有其他错误。有一个谷歌,但什么都找不到——我想我会在这里问,以防你看到类似的东西。这一切都在本地工作;也许错过了安装?
    • 啊,我认为 sox 错误代码是一个红鲱鱼......也许我的谷歌信用没有授权。现在看。
    • 我的错误在于我尝试访问麦克风流的位置。谁能想到任何可能丢失的东西?毫无疑问,显而易见的事情:( - 它在本地工作。有问题的代码:``` const recorder = require('node-record-lpcm16'); recorder .record({ sampleRateHertz: 16000, threshold: 0, verbose: false, recordProgram : 'rec', 静音: '10.0', }) .stream() .on('error', (error) => console.log('ERROR with recorder.record', error)) .pipe(recognizeStream); ``` 输出:ERROR with record.record sox has exited with error code 2.
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-03-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-11
    • 1970-01-01
    • 2023-04-09
    相关资源
    最近更新 更多