Google Speech-to-Text does not transcribe in multiple languages - Stack Overflow

The google transcription service does not identify multiple languages in the registration. Below is my

The google transcription service does not identify multiple languages in the registration. Below is my code. I have used different formats (MP3, MP4 and FLAC) and models. But it still doesn't work. This is just a code variant.

What could be the problem why it does not transcribe in multiple languages?

Code for MP3:

new Promise(async (resolve, reject) => {
    const request = {
        config: {
            encoding: "MP3",
            sampleRateHertz: 16000,
            audioChannelCount: 2,
            languageCode: ["en-US"],
            alternativeLanguageCodes: ["es-ES", "fr-FR", "en-US"],
            useEnhanced: true,
            enableWordConfidence: true,
            enableWordTimeOffsets: true,
            enableAutomaticPunctuation: true
        },
        audio: {
            uri: `gs://${process.env.GOOGLE_CLOUD_STORAGE_BUCKET_SCRIPTOMAN}/multilingual.mp3`
        }
    };

    let [operation] = [];

    try {
        [operation] = await googleSpeechClient.longRunningRecognize(request);
    } catch {
        try {
            request.config.audioChannelCount = 1;

            [operation] = await googleSpeechClient.longRunningRecognize(request);
        } catch (error) {
            reject(error);
        }
    }

    if ([operation] != undefined && operation != undefined) {
        const [response] = await operation.promise();

        resolve(response.results);
    } else
        reject();
}).then(results => {
    console.log(results);
}).catch(error => console.log(error));

Code for FLAC:

new Promise(async (resolve, reject) => {
    const request = {
        config: {
            encoding: "FLAC",
            audioChannelCount: 2,
            languageCode: ["en-US"],
            alternativeLanguageCodes: ["es-ES", "fr-FR", "en-US"],
            enableWordConfidence: true,
            enableWordTimeOffsets: true,
            enableAutomaticPunctuation: true
        },
        audio: {
            uri: `gs://${process.env.GOOGLE_CLOUD_STORAGE_BUCKET_SCRIPTOMAN}/multilingual.flac`
        }
    };

    let [operation] = [];

    try {
        [operation] = await googleSpeechClient.longRunningRecognize(request);
    } catch {
        try {
            request.config.audioChannelCount = 1;

            [operation] = await googleSpeechClient.longRunningRecognize(request);
        } catch (error) {
            reject(error);
        }
    }

    if ([operation] != undefined && operation != undefined) {
        const [response] = await operation.promise();

        resolve(response.results);
    } else
        reject();
}).then(results => {
    console.log(results);
}).catch(error => console.log(error));

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744760119a4592122.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信