ReactJS – Google Cloud Voice with React Native

I am trying to use Google Cloud Speech API, so I can pass audio files and receive translated text but I still stick to the integration. I already have the api key and everything I need, but Can’t find how to use the response itself. There is only node.js explanation in the documentation (from the javascript part). There are also several libraries that are outdated or only support one operating system. Has anyone succeeded?

Node.js example in the document:

// 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< br />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}`);
});

Deploy this server to Heroku, and then send a post from your react native app or get a request to this server and get the result on your app.
To send a post or get a request, use the Axios library https://github.com/axios /axios

I am trying to use Google Cloud Speech API, so I can pass audio files and receive translated text but I still stick to the integration. I already have the api key and everything needed , But can’t find how to use the response itself. There is only node.js explanation in the documentation (from the javascript part). There are also several libraries that are outdated or only support one operating system. Has anyone succeeded?

Node.js example in the document:

// 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< br />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}`);
});

< p>Deploy this server to Heroku, then send a post from your react native app or get a request to this server and get the result on your app.
To send a post or get a request, use the Axios library https://github.com/axios/axios

Leave a Comment

Your email address will not be published.