在谷歌云上设置谷歌语音到文本-错误:生成SoX ENOENT



我学习了一系列关于谷歌语音到文本的教程,并在本地运行良好。我的设置是使用websockets(socket.io(在客户端Angular应用程序和对语音API进行服务器端调用的node/express后端之间进行通信。我正在使用streaming-recognize(https://cloud.google.com/speech-to-text/docs/streaming-recognize(读取麦克风流并返回结果。

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

我认为我需要建立一个可以用SoX提供的虚拟机实例,但也觉得这似乎有点过头了——有其他选择吗?我确实尝试过手动解析麦克风数据流并将其发送为Uint8Array/ArrayBuffer块,取得了一些成功,但并不多。我还读到一些关于非SoX方法处理用户麦克风流的假设,但没有用。例如有记录。

问题是,我需要做什么才能在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 Speech to Text,并希望将其部署在Google应用程序引擎上(gcloud应用程序部署(。

然而,Google Speech to Text有一个Sox依赖项,这需要在操作系统中安装Sox CLI。

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

我能够使用quickstart中提供的步骤和nodejs-Speech存储库中的示例代码成功部署一个使用Speech-to-Textneneneba API的AppEngineFlex应用程序。请看一下。

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

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的一个示例。

最新更新