gpt4 book ai didi

electron - 谷歌云语音在 Electron package 中不起作用

转载 作者:行者123 更新时间:2023-12-03 12:23:17 28 4
gpt4 key购买 nike

当我使用npm start命令从命令提示符运行应用程序时,它运行良好。它从语音API返回结果。

我正在使用binaryServer和binaryclient将音频流传输到Google Cloud API。

当我创建用于 Electron 应用的程序包时,一切正常,但不会从语音API返回结果。

这是我的代码片段:
Package.json

{
"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版本(本地版本)为目标的 native 二进制文件。当您生成子进程时,它使用相同的本地版本。

但是,打包 Electron 应用程序时,它将尝试使用Electron版本的V8生成该过程,并且会出现二进制不兼容的情况。

简单地说
[您的V8版本]!= [ Electron 的V8版本]

寻求潜在的解决方案

  • Sonus
    Electron 提供您
  • 用以下命令重新编译依赖项
    electron-recompile
  • 关于electron - 谷歌云语音在 Electron package 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41186878/

    28 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com