【问题标题】:Google Speech To Text only recognizes a single wordGoogle Speech To Text 只能识别一个单词
【发布时间】:2022-10-18 16:06:16
【问题描述】:

我有一个超过 2 分钟的 flac 音频文件。

在这里你可以看到它:

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

当我使用 ffprobe 获取文件的元数据时,我看到音频文件有 2 个通道和 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)

我想像这样使用Google Speech To Text识别它:

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

结果我收到了

{
    "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"
    }
}

音频文件中有很多单词。

我到底做错了什么?

【问题讨论】:

  • 您的 response.results[] 数组可能包含多个条目。您可以使用循环检查吗?
  • @kiranmathew 我也尝试过,但不幸的是,该数组只有一个元素。
  • 对于多声道音频,您还需要在配置中添加enableSeparateRecognitionPerChannel: true。但即使没有添加,我已经实现了与您和我的环境相同的配置,并且得到了比您更好的响应(超过 1 个字)。您如何检查response 数据?
  • @kiranmathew 太奇怪了。我认为这与我检查响应的方式无关,因为我一直在检索一个单词,响应中没有其他数据。您是否对音频文件进行了任何其他操作?

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


【解决方案1】:

我检查了音频文件。我不确切知道,但是当我将 flac 格式转换为 wav 格式时,代码可以正常工作。

命令:ffmpeg -i input.flac output.wav

但是对于 flac 格式,这个过程不像你说的那样工作。

【讨论】:

    猜你喜欢
    • 2017-06-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-05-03
    • 1970-01-01
    相关资源
    最近更新 更多