2017-02-27 119 views
2

我想使用Google云语音API,因此我可以传递音频文件并接收翻译文本,但我坚持整合。我已经有API密钥和所需的一切,但无法找到如何使用它从原生反应。在文档中只有node.js的解释(来自javascript部分)。还有几个库过期或只支持一个操作系统。有人成功了吗?Google云语音与React Native

从文档Node.js的例子:

// Imports the Google Cloud client library 
const Speech = require('@google-cloud/speech'); 

// Your Google Cloud Platform project ID 
const projectId = 'YOUR_PROJECT_ID'; 

// Instantiates a client 
const speechClient = Speech({ 
    projectId: projectId 
}); 

// The name of the audio file to transcribe 
const fileName = './resources/audio.raw'; 

// The audio file's encoding and sample rate 
const options = { 
    encoding: 'LINEAR16', 
    sampleRate: 16000 
}; 

// Detects speech in the audio file 
speechClient.recognize(fileName, options) 
    .then((results) => { 
    const transcription = results[0]; 
    console.log(`Transcription: ${transcription}`); 
    }); 
+0

你只需要开发自己的实现,为Android和iOS创建本地模块。 –

回答

0

部署此服务器的Heroku然后从你的反应,本机应用程序发送的帖子或get请求到该服务器,并获得您的应用程序的结果。 发送帖子或获取请求使用Axios库https://github.com/axios/axios