2016-12-16 6 views
1

npm startコマンドを使用してコマンドプロンプトからアプリケーションを実行すると、うまく動作します。スピーチAPIからの結果を返します。googleクラウドスピーチが電子パッケージで動作しない

私は、Google Cloud APIにオーディオをストリーミングするためにbinaryServerとbinaryclientを使用しています。

電子アプリケーション用のパッケージを作成すると、すべて機能しますが、音声APIから結果が返されません。ここで

は、私のコードのsnippeです: 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"); 
    }); 
}); 

おかげで

答えて

0

ここで暗闇の中で撮影します(現実的には問題になる可能性のあるbi​​naryServerに精通していなくても)。私はまた、オーディオストリームが実際にどこから来るのかについて少しはっきりしていません。

電子パッケージはV8のそれ自身のバージョンです。 npm installを実行すると、マシン(ローカルバージョン)にインストールされているV8のバージョンを対象とするネイティブバイナリがインストール(またはオンザフライでコンパイル)されます。子プロセスを起動すると、同じローカルバージョンが使用されます。

電子アプリをパッケージ化すると、電子版のV8でプロセスを生成しようとしますが、バイナリの非互換性があります。入れ

は単に 潜在的な解決策

  • Sonusにオン[V8のバージョン]!= [V8のエレクトロンのバージョン]

    は エレクトロンが提供と互換性があることをあなた

  • 再-compile dependencies with electron-recompile
関連する問題