问题描述
您好,我想在Google Home上制作自定义的api。
方法是语音转文本(stt)->自然语言处理(NLP)->使用IP端口控制我的智能灯。
所以,我正在测试Microphonestream.js。但是,我遇到了错误。
**Listening,press Ctrl+C to stop.
sox has exited with error code 1.
Enable debugging with the environment variable DEBUG=record.**
'use strict';
/**
* Note: Correct microphone settings is required: check enclosed link,and make
* sure the following conditions are met:
* 1. SoX must be installed and available in your $PATH- it can be found here:
* http://sox.sourceforge.net/
* 2. Microphone must be working
* 3. Encoding,sampleRateHertz,and # of channels must match header of audio file you're
* recording to.
* 4. Get Node-Record-lpcm16 https://www.npmjs.com/package/node-record-lpcm16
* More Info: https://cloud.google.com/speech-to-text/docs/streaming-recognize
*/
// const encoding = 'LINEAR16';
// const sampleRateHertz = 16000;
// const languageCode = 'en-US';
function microphonestream(encoding,languageCode) {
// [START micStreamRecognize]
// Node-Record-lpcm16
const recorder = require('node-record-lpcm16');
// Imports the Google Cloud client library
const speech = require('@google-cloud/speech');
const config = {
encoding: encoding,sampleRateHertz: sampleRateHertz,languageCode: languageCode,};
const request = {
config,interimResults: false,//Get interim results from stream
};
// Creates a client
const client = new speech.SpeechClient();
// Create a recognize stream
const recognizeStream = client
.streamingRecognize(request)
.on('error',console.error)
.on('data',data =>
process.stdout.write(
data.results[0] && data.results[0].alternatives[0]
? `Transcription: ${data.results[0].alternatives[0].transcript}\n`
: '\n\nReached transcription time limit,press Ctrl+C\n'
)
);
// Start recording and send the microphone input to the Speech API
recorder
.record({
sampleRateHertz: sampleRateHertz,threshold: 0,//silence threshold
recordProgram: 'rec',// Try also "arecord" or "sox"
silence: '5.0',//seconds of silence before ending
})
.stream()
.on('error',console.error)
.pipe(recognizeStream);
console.log('Listening,press Ctrl+C to stop.');
// [END micStreamRecognize]
}
require('yargs')
.demand(1)
.command(
'micStreamRecognize','Streams audio input from microphone,translates to text',{},opts =>
microphonestream(opts.encoding,opts.sampleRateHertz,opts.languageCode)
)
.options({
encoding: {
alias: 'e',default: 'LINEAR16',global: true,requiresArg: true,type: 'string',},sampleRateHertz: {
alias: 'r',default: 16000,type: 'number',languageCode: {
alias: 'l',default: 'en-US',})
.example('node $0 micStreamRecognize')
.wrap(120)
.recommendCommands()
.epilogue('For more @R_854_4045@ion,see https://cloud.google.com/speech/docs')
.help()
.strict().argv;
下面是我的package.json
{
"name": "@google-cloud/speech","description": "Cloud Speech Client Library for Node.js","version": "4.1.1","license": "Apache-2.0","author": "Google Inc.","engines": {
"node": ">=10"
},"repository": "googleapis/nodejs-speech","main": "./build/src/index.js","files": [
"build/protos","build/src","AUTHORS","LICENSE"
],"keywords": [
"Google Apis client","Google Api client","Google Apis","Google Api","google","google cloud platform","google cloud","cloud","google speech","speech","Google Cloud Speech API"
],"scripts": {
"docs": "jsdoc -c .jsdoc.js","lint": "gts check","samples-test": "cd samples/ && npm link ../ && npm test && cd ../","system-test": "c8 mocha build/system-test/*.js --timeout 600000","test": "c8 mocha build/test/*.js","fix": "gts fix","docs-test": "linkinator docs","predocs-test": "npm run docs","compile": "tsc -p . && cp system-test/*.js build/system-test/ && cp -r protos build/","prepare": "npm run compile","pretest": "npm run compile","prelint": "cd samples; npm link ../; npm install","clean": "gts clean","precompile": "gts clean","api-extractor": "api-extractor run --local","api-documenter": "api-documenter yaml --input-folder=temp"
},"dependencies": {
"@google-cloud/common": "^3.0.0","google-gax": "^2.1.0","protobufjs": "^6.8.6","pumpify": "^2.0.0","stream-events": "^1.0.4","@types/pumpify": "^1.4.1"
},"devDependencies": {
"@types/mocha": "^8.0.0","@types/node": "^12.0.0","@types/sinon": "^9.0.0","c8": "^7.0.0","codecov": "^3.0.2","gts": "^2.0.0","jsdoc": "^3.5.5","jsdoc-fresh": "^1.0.1","jsdoc-region-tag": "^1.0.2","linkinator": "^2.0.0","mocha": "^8.0.0","null-loader": "^4.0.0","pack-n-play": "^1.0.0-2","sinon": "^9.0.1","ts-loader": "^8.0.0","typescript": "^3.8.3","webpack": "^4.41.2","webpack-cli": "^3.3.10","@microsoft/api-documenter": "^7.8.10","@microsoft/api-extractor": "^7.8.10"
}
}
专家,我需要您的帮助。拜托。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)