我正在尝试使用Google Cloud Speech API,因此我可以传递音频文件并接收翻译文本但我仍然坚持使用集成.我已经有api密钥和所需的一切,但无法找到如何使用它本身的反应.在文档中只有node.j
文档中的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}`); });将此服务器部署到Heroku,然后从您的react本机应用程序发送帖子或获取请求到此服务器并在您的应用程序上获得结果.
要发送帖子或获取请求,请使用Axios库 https://github.com/axios/axios