Hello i want to make a customized api on Google Home.
The way it's going is speech-to-text(stt) -> Natural Language Processing(NLP) -> Control my smart-light using IP, port.
So, i'm testing MicrophoneStream.js. but, i got an error.
**Listening, press Ctrl+C to stop.
sox has exited with error code 1.
Enable debugging with the environment variable DEBUG=record.**
Below, it is code about MicrophoneStream.js
'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, sampleRateHertz, 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,
global: true,
requiresArg: true,
type: 'number',
},
languageCode: {
alias: 'l',
default: 'en-US',
global: true,
requiresArg: true,
type: 'string',
},
})
.example('node $0 micStreamRecognize')
.wrap(120)
.recommendCommands()
.epilogue('For more information, see https://cloud.google.com/speech/docs')
.help()
.strict().argv;
Below it is my 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"
}
}
I need your help, experts. Please.