【问题标题】:Save speech to text in local using node js使用节点 js 将语音保存到本地文本
【发布时间】:2018-07-18 07:57:55
【问题描述】:

我正在尝试复制https://github.com/googleapis/nodejs-speech/blob/master/samples/recognize.js 给出的代码。我在本地运行它时没有错误。但是在这里,我对在哪里可以看到创建的结果感到困惑。有没有办法可以将结果写入文件?

这里是代码。

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();

/**
 * TODO(developer): Uncomment the following lines before running the sample.
 */
const encoding = 'LINEAR16';
const sampleRateHertz = 16000;
const languageCode = 'en-US';

const request = {
    config: {
        encoding: encoding,
        sampleRateHertz: sampleRateHertz,
        languageCode: languageCode,
    },
    interimResults: false, // If you want interim results, set this to true
};

// 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`
        )
    );

// Start recording and send the microphone input to the Speech API
record
    .start({
        sampleRateHertz: sampleRateHertz,
        threshold: 0,
        // Other options, see https://www.npmjs.com/package/node-record-lpcm16#options
        verbose: false,
        recordProgram: 'sox', // Try also "arecord" or "sox"
        silence: '10.0',
    })
    .on('error', console.error)
    .pipe(recognizeStream);

console.log('Listening, press Ctrl+C to stop.');

这很令人困惑 :(。请告诉我如何实现这一点。

谢谢

【问题讨论】:

    标签: node.js speech-to-text google-cloud-speech


    【解决方案1】:

    它在“数据”中。请查看the code 并查看控制台如何记录数据。

    例子:

    client
    .recognize(request)
    .then(data => {
      const response = data[0];
      const transcription = response.results
        .map(result => result.alternatives[0].transcript)
        .join('\n');
      console.log(`Transcription: `, transcription);
    })
    

    【讨论】:

      猜你喜欢
      • 2018-09-27
      • 1970-01-01
      • 2013-04-07
      • 1970-01-01
      • 2016-01-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多