如何从.wav文件中转录完整的音频文本?

问题描述 投票:0回答:1

它不会转录完整的音频文件,并且在转录完整的音频文件之前正在执行该过程。它只转录音频文件的前几秒。

我提到了这个https://docs.microsoft.com/en-us/azure/cognitive-services/speech-service/quickstart-js-node#prerequisites

有人可以帮我解决这个问题吗?

// pull in the required packages.
var sdk = require("microsoft-cognitiveservices-speech-sdk");
var fs = require("fs");

var axios = require('axios')

// replace with your own subscription key,
// service region (e.g., "westus"), and
// the name of the file you want to run
// through the speech recognizer.
var subscriptionKey = "";
var serviceRegion = ""; // e.g., "westus"
var filename = "output2.wav"; // 16000 Hz, Mono

// create the push stream we need for the speech sdk.
var pushStream = sdk.AudioInputStream.createPushStream();

// open the file and push it to the push stream.
fs.createReadStream(filename).on('data', function (arrayBuffer) {
    // console.log(arrayBuffer);
    pushStream.write(arrayBuffer.buffer);
}).on('end', function () {
    pushStream.close();
});

// we are done with the setup
console.log("Now recognizing from: " + filename);

// now create the audio-config pointing to our stream and
// the speech config specifying the language.
var audioConfig = sdk.AudioConfig.fromStreamInput(pushStream);
var speechConfig = sdk.SpeechConfig.fromSubscription(subscriptionKey, serviceRegion);

// setting the recognition language to English.
speechConfig.speechRecognitionLanguage = "en-US";

// create the speech recognizer.
var recognizer = new sdk.SpeechRecognizer(speechConfig, audioConfig);

// start the recognizer and wait for a result.
recognizer.recognizeOnceAsync(
    function (result) {
        console.log(result);

        recognizer.close();
        recognizer = undefined;
    },
    function (err) {
        console.trace("err - " + err);

        recognizer.close();
        recognizer = undefined;
    });
node.js azure speech-to-text
1个回答
1
投票

您需要使用StartContinuousRecognitionAsync而不是recognOnceAsync

© www.soinside.com 2019 - 2024. All rights reserved.