Murat Colyaran
Murat Colyaran

Reputation: 2189

Google Speech To Text only recognizes a single word

I have a flac audio file longer than 2 minutes.

You can see it here:

https://drive.google.com/file/d/1yNqVT_FBPyNurQW7URymGvfXLwTJb60F/view?usp=sharing

When I get metadata of the file with ffprobe I see the audio file has 2 channels and 44100 Hz

ffprobe ./c2b30307-89b5-4091-8712-388812d8fd06.flac

Input #0, flac, from './c2b30307-89b5-4091-8712-388812d8fd06.flac':
  Metadata:
    encoder         : Lavf58.29.100
  Duration: 00:02:39.17, start: 0.000000, bitrate: 424 kb/s
    Stream #0:0: Audio: flac, 44100 Hz, stereo, s32 (24 bit)

And I want to use Google Speech To Text recognize on it like this:

import speech from "@google-cloud/speech";

const client = new speech.SpeechClient({
    keyFile: "/foo/bar/gcloud_credentials.json"
});
const [operation] = await client.longRunningRecognize({
    audio: {
        uri: "gs://" + fileCloudPath // Using uri because some audios exceeds duration limit
    },
    config: {
        encoding: "FLAC",
        languageCode: "nl-NL",
        enableWordTimeOffsets: true,
        audioChannelCount: 2,
        sampleRateHertz: 44100
    }
});

const [response] = await operation.promise();

And result I'm receiving

{
    "results": [
        {
            "alternatives": [
                {
                    "transcript": "hallo",
                    "confidence": 0.9460594058036804,
                    "words": [
                        {
                            "startTime": {},
                            "endTime": {
                                "seconds": "6",
                                "nanos": 300000000
                            },
                            "word": "hallo"
                        }
                    ]
                }
            ],
            "resultEndTime": {
                "seconds": "21",
                "nanos": 810000000
            },
            "languageCode": "nl-nl"
        }
    ],
    "totalBilledTime": {
        "seconds": "30"
    }
}

There are a lot of words in the audio file.

What exactly am I doing wrong?

Upvotes: 1

Views: 187

Answers (1)

Emin
Emin

Reputation: 46

I examined the audio file. I don't know exactly, but when I convert the flac format to wav format, the code works without any problems.

Command: ffmpeg -i input.flac output.wav

But with flac format this process doesn't work as you said.

Upvotes: 3

Related Questions