React-Native语音到文本

时间:2017-01-28 00:09:53

标签: react-native speech-recognition speech-to-text watson-conversation watson

我正在尝试使用Watson Speech to Text API在react-native应用程序中录制音频,然后将音频转换为文本。

我无法搞清楚这一点,任何帮助都会非常感激。

我可以录制音频,但我无法弄清楚如何将文件发送到后端或只是直接发送到前端的Watson API。

节点的Watson API Cloud库具有:

      var SpeechToTextV1 = require('watson-developer-cloud/speech-to-text/v1');
      var fs = require('fs');

      var speech_to_text = new SpeechToTextV1({
      username: '<username>',
      password: '<password>'
      });

        var params = {
        // From file
        audio: fs.createReadStream('./resources/speech.wav'),
        content_type: 'audio/l16; rate=44100'
         };

       speech_to_text.recognize(params, function(err, res) {
       if (err)
       console.log(err);
       else
      console.log(JSON.stringify(res, null, 2));
       });

不幸的是,我无法访问前端的'fs'来创建Streams。该文件保存在客户端前端的隐藏文件夹中(我也有路径)

最终我想以某种方式创建一个流,以便我可以发送音频,以便自动转换为文本并降低速度。

像这样:

   fs.createReadStream('./resources/speech.wav')
   .pipe(speech_to_text.createRecognizeStream({ content_type:       'audio/l16; rate=44100' }))
  .pipe(fs.createWriteStream('./transcription.txt'));

任何想法如何在前端使用录制音频的路径完成所有这些操作。有什么工作吗?谢谢!

1 个答案:

答案 0 :(得分:2)

React Native支持开箱即用的websockets:https://facebook.github.io/react-native/docs/network.html

Watson API支持websockets作为其Speech to Text API的一部分:https://www.ibm.com/watson/developercloud/doc/speech-to-text/websockets.shtml(请参阅“发送音频和接收识别结果”一节websocket.send(blob)

这似乎是一个合理的解决方案。

相关问题