title: Implementing Google Cloud Speech-to-Text on React-Native
body: <p>I'm trying to implement google's speech-to-text on a react native app but I can't find an example or documentation about it, I'm fairly new to react-native so I'm kinda lost, there's a <a href="https://cloud.google.com/speech-to-text/docs/quickstart-client-libraries#client-libraries-usage-nodejs" rel="nofollow noreferrer">sample using node.js</a> on google official docs and I'm trying to 'copy' it to react-native but I didn't had any success.</p>
  
  <p>Here's the Node.js example:</p>
  
  <pre><code>async function main() {
    // Imports the Google Cloud client library
    const speech = require('@google-cloud/speech');
    const fs = require('fs');
  
    // Creates a client
    const client = new speech.SpeechClient();
  
    // The name of the audio file to transcribe
    const fileName = './resources/audio.raw';
  
    // Reads a local audio file and converts it to base64
    const file = fs.readFileSync(fileName);
    const audioBytes = file.toString('base64');
  
    // The audio file's encoding, sample rate in hertz, and BCP-47 language code
    const audio = {
      content: audioBytes,
    };
    const config = {
      encoding: 'LINEAR16',
      sampleRateHertz: 16000,
      languageCode: 'en-US',
    };
    const request = {
      audio: audio,
      config: config,
    };
  
    // Detects speech in the audio file
    const [response] = await client.recognize(request);
    const transcription = response.results
      .map(result =&gt; result.alternatives[0].transcript)
      .join('\n');
    console.log(`Transcription: ${transcription}`);
  }
  main().catch(console.error);
  </code></pre>
  
  <p>First of all, the 'fs' package doesn't work on react-native, so I had to use 'react-native-fs' which has different functions</p>
  
  <p>Second, should I really use the 'require' to call the speech package? I guess react-native would use 'import' instead, right?</p>
  
  <p>Any tips on how can I implement it on react-native? Thanks!</p>