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



它不是转录完整的音频文件,在转录完整的音频文件之前,这个过程令人兴奋。它只是转录音频文件的前几秒钟。

我提到了这个 https://learn.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;
    });

你需要使用 StartContinuRecognitionAsync 而不是 recognizeOnceAsync

最新更新