Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

164
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda