谷歌语音到文本API在React Native问题中

时间:2018-10-24 23:03:05

标签: react-native speech-to-text google-speech-api

我正在尝试将以下示例转换为可在react应用中使用的代码。我已经尝试过使用抓取功能,但这对我来说还行不通。如果有一个例子,请告诉我。

const record = require("node-record-lpcm16");

// Imports the Google Cloud client library
const speech = require("@google-cloud/speech");

// Creates a client
const client = new speech.SpeechClient();

const encoding = "LINEAR16";
const sampleRateHertz = 16000;
const languageCode = "en-US";

const request = {
  config: {
    encoding: encoding,
    sampleRateHertz: sampleRateHertz,
    languageCode: languageCode
  },
  interimResults: false 
};

// Create a recognize stream
const recognizeStream = client
  .streamingRecognize(request)
  .on("error", console.error)
  .on("data", data =>
    process.stdout.write(
      data.results[0] &&         data.results[0].alternatives[0]
    ? `Transcription: ${data.results[0].alternatives[0].transcript}\n`
    : `\n\nReached transcription time limit, press Ctrl+C\n`));

0 个答案:

没有答案