Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

162
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda