【发布时间】:2017-07-18 06:55:19
【问题描述】:
我正在尝试使用 Google Cloud Speech API,以便我可以传递音频文件并接收翻译后的文本,但我坚持使用集成。我已经有了 api 密钥和所需的一切,但无法从 react native 中找到如何使用它。在文档中只有对 node.js 的解释(来自 javascript 部分)。还有几个库过时或仅支持一个操作系统。有人成功了吗?
文档中的 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}`);
});
【问题讨论】:
-
您只需要通过为 android 和 iOS 制作本机模块来开发自己的实现。
标签: reactjs react-native google-cloud-speech