Electron 谷歌云语音在电子包中不起作用
当我使用npmstart命令从命令提示符运行应用程序时,它运行得很好。它从语音api返回结果 我正在使用binaryServer和binaryclient将音频流传输到google云API 当我为electron应用程序创建包时,一切正常,但它不会从SpeechAPI返回结果 以下是我的代码: Package.jsonElectron 谷歌云语音在电子包中不起作用,electron,electron-builder,google-cloud-speech,Electron,Electron Builder,Google Cloud Speech,当我使用npmstart命令从命令提示符运行应用程序时,它运行得很好。它从语音api返回结果 我正在使用binaryServer和binaryclient将音频流传输到google云API 当我为electron应用程序创建包时,一切正常,但它不会从SpeechAPI返回结果 以下是我的代码: Package.json { "name": "test", "version": "1.0.0", "description": "test Web Server", "main": "
{
"name": "test",
"version": "1.0.0",
"description": "test Web Server",
"main": "main.js",
"scripts": {
"start": "electron main.js"
},
"devDependencies": {
"electron": "^1.4.12"
},
"dependencies": {
"binaryjs": "^0.2.1",
"connect": "^3.3.4",
"biased-opener": "^0.2.8",
"serve-static": "^1.9.1",
"uaparser": "^0.0.2",
"@google-cloud/speech" : "^0.5.0"
}
}
这是我的main.js
app.on('ready', function () {
load_app();
});
var workerProcess = child_process.spawn('node', __dirname + '/binaryServer.js');
workerProcess.stdout.on('data', function (data) {
console.log('stdout: ' + data);
});
workerProcess.stderr.on('data', function (data) {
console.log('stderr: ' + data);
});
workerProcess.on('close', function (code) {
console.log('child process exited with code ' + code);
});
processes.push(workerProcess);
function load_app () {
// Launches the browser window
mainWindow = new BrowserWindow({ width: 1080, height: 1920 });
// Load just launched server in browser window
mainWindow.loadURL("http://localhost:" + config.port);
if (config.devMode) {
mainWindow.webContents.openDevTools();
}
else {
mainWindow.setFullScreen(true);
}
}
这是我的二进制服务器
var binaryServer = require('binaryjs').BinaryServer,
https = require('http'),
connect = require('connect'),
serveStatic = require('serve-static');
var config = require('./config');
var server = connect()
.use(serveStatic(__dirname));
var speech = require('@google-cloud/speech')({
projectId: config.speech.projectId,
keyFilename: config.speech.keyFilename
});
httpServer = https.createServer(server);
httpServer.timeout = 0;
httpServer.listen(config.port);
var binarySer = binaryServer({ server: httpServer });
console.log("server pid" + process.pid);
binarySer.on('connection', function (client) {
console.log("new connection...");
client.on('stream', function (stream, meta) {
var options = {
config: {
encoding: 'LINEAR16',
sampleRate: meta.sampleRate,
languageCode: "en-IN"
},
singleUtterance: false,
interimResults: true,
verbose: true
};
// Create a recognize stream
const recognizeStream = speech.createRecognizeStream(options)
.on('error', console.error)
.on('data', function (data) { if (stream.writable && !stream.destroyed) stream.write(data) }); // send data to client
if (recognizeStream.writable && !recognizeStream.destroyed && stream.readable && !stream.destroyed)
stream.pipe(recognizeStream); // pipe audio to cloud speech
});
client.on('close', function () {
console.log("Connection Closed");
});
});
感谢您的帮助在这里暗中拍摄(不太熟悉binaryServer,这实际上可能是个问题)。我也有点不清楚音频流的实际来源: Electron打包了自己版本的V8。当您运行
npm install
时,它将安装(或动态编译)针对您机器上安装的V8版本(本地版本)的本机二进制文件。生成子进程时,它使用相同的本地版本
然而,当你打包你的electron应用程序时,它会试图用electron版本的V8生成这个过程,并且会出现二进制不兼容
简言之
[您的V8版本]!=[Electron的V8版本]
了解潜在的解决方案
- 兼容 如果你
- 使用重新编译依赖项