cha*_*ary 5 reactjs react-native google-cloud-speech
我正在尝试使用 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}`);
});
Run Code Online (Sandbox Code Playgroud)
将此服务器部署到 Heroku,然后从您的 React Native 应用程序向此服务器发送 post 或 get 请求,并在您的应用程序上获取结果。要发送帖子或获取请求,请使用 Axios 库https://github.com/axios/axios
| 归档时间: |
|
| 查看次数: |
1415 次 |
| 最近记录: |