【发布时间】:2019-03-10 17:43:49
【问题描述】:
我想将Google Speech to Text engine 与我的麦克风关联。
我找到了this 页面,将代码复制到我的renderer.ts 文件中(取消注释带有const 的行),但是在运行时- 由于第7 行(const client = new speech.SpeechClient();)而出现以下错误:
@987654323 @
是的,我确实尝试同时运行 yarn install --force(因为我主要使用 Yarn)和 npm rebuild,以及 yarn add grpc,但问题仍然存在。
renderer.ts:
const record = require('node-record-lpcm16');
// Imports the Google Cloud client library
const speech = require('@google-cloud/speech');
// Creates a client
const client = new speech.SpeechClient();
/**
* TODO(developer): Uncomment the following lines before running the sample.
*/
const encoding = 'LINEAR16';
const sampleRateHertz = 16000;
const languageCode = 'en-US';
const request = {
config: {
encoding: encoding,
sampleRateHertz: sampleRateHertz,
languageCode: languageCode,
},
interimResults: false, // If you want interim results, set this to true
};
// 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
record
.start({
sampleRateHertz: sampleRateHertz,
threshold: 0,
// Other options, see https://www.npmjs.com/package/node-record-lpcm16#options
verbose: false,
recordProgram: 'rec', // Try also "arecord" or "sox"
silence: '10.0',
})
.on('error', console.error)
.pipe(recognizeStream);
console.log('Listening, press Ctrl+C to stop.');
感谢您的帮助!
【问题讨论】:
-
你能分享你的代码吗?
-
您是否尝试过自己安装 gRPC 二进制模块(如错误所述)?
-
@Ahm。我从字面上复制了我链接的第二页 - 第二个代码块,它没有工作。
-
@Grynets 我也试过了,但没有运气。
-
你确定它是相关的吗?该存储库是关于 Electron、Go 和 gRPC 之间的集成。我不是在 Go 中编程
标签: node.js typescript speech-recognition