我已经按照一堆关于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 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的示例。
非常感谢您的指导!看起来非常有前途。我已经进行了一些研究,并尝试按照以下步骤进行设置:github.com/GoogleCloudPlatform / ... 我在进行操作时遇到了一些困难-您是否有一个Dockerfile的示例,可以用来使我的Flexible env运行,安装了SoX?
我更新了答案,请查看一下。
太棒了,谢谢你!整理了到目前为止我遇到的所有错误-现在得到了一个有点神秘的错误
sox has exited with error code 2.
。拖曳时,没有其他高于或低于此错误gcloud app logs tail
。曾经有一个谷歌,但什么也没找到。我想在这里问一下,以防你看到类似的东西。这一切都在本地工作;也许缺少安装?嗯,我认为sox错误代码是红色鲱鱼...也许我的google信用没有被授权。现在看。
我的错误是在尝试访问麦克风流的地方。谁能想到任何可能丢失的东西?毫无疑问是显而易见的:(-它在本地工作。正在讨论的代码:```constrecorder = require('node-record-lpcm16'); recorder .record({sampleRateHertz:16000,threshold:0,verbose:false,recordProgram :'rec',沉默:'10 .0',}).stream().on('error',(错误)=> console.log('error withrecorder.record',error)).pipe(recognizeStream); ```输出:
ERROR with record.record sox has exited with error code 2.