Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

161
Views
Using Google Speech REST APi from Node without helper module

I'm just getting started with a simple project in node.js.

I'm trying to use Expo for the final app but get lots of dependency conflicts in the modules so was thinking of just calling the REST API via fetch. I have a test bed that works fine using the google-supplied modules, but I always get RecognitionAduio is not supplied as an error message via REST. As you can see in the attached code, the input file, coding etc are all identical.

any views?

async function getAudioTranscription()  {
  const fetch = require("node-fetch");
  try {

    var filename = 'C:/Users/SteveRist/Downloads/brooklyn.flac';
    var encoding = 'FLAC';
    var sampleRateHertz = 16000;
    var languageCode = 'en-US';
    const fs = require('fs');
    const speech = require('@google-cloud/speech');
    const client = new speech.SpeechClient();
    console.log ('Setting REST config');
  
    const config = {
      encoding: encoding,
      sampleRateHertz: sampleRateHertz,
      languageCode: languageCode,
    };
  
    console.log ('opening ', filename);
    const audio = {
      content: fs.readFileSync(filename).toString('base64'),
    };
  
    const request = {
      config: config,
      audio: audio,
    };

    
    // Detects speech in the audio file. This creates a recognition job that you
    // can wait for now, or get its result later.
    const [operation] = await client.longRunningRecognize(request);
  
    // Get a Promise representation of the final result of the job
    const [response] = await operation.promise();
    const transcription = response.results
      .map(result => result.alternatives[0].transcript)
      .join('\n');
    console.log(`Transcription: ${transcription}`);
       
    const transcriptResponse = await fetch(
        'https://speech.googleapis.com/v1/speech:recognize?key=xxx8', {
          method: 'POST',
          request: request
        }
      );

      const data = await transcriptResponse.json();
      console.log ('transcriptResponse Google returned' , data);
      const userMessage = data.results && data.results[0].alternatives[0].transcript || "";
        console.log (userMessage);
 
  } catch (error) {
    console.log("There was an error", error);
  }
  
}
  getAudioTranscription();
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!