谷歌云语音到文本长音频响应

时间:2019-11-23 16:49:39

标签: google-cloud-platform speech-recognition speech-to-text google-speech-api google-cloud-speech

我正在尝试将音频转换为文本,但是得到的结果是

LongRunningRecognizeResponse { results: [] }

这是我的职责,

    const audio = {
    uri: `gs://${BUCKET}/${fileName}`,
};

const request = {
    config: {
        encoding: 'LINEAR16',
        sampleRateHertz: 16000,
        languageCode: 'en-US',
    },
    audio: audio,
};

client.longRunningRecognize(request)
    .then(responses => {
        const [operation, initialApiResponse] = responses;

        operation.on('complete', (result, metadata, finalApiResponse) => {
            console.log('complete', result) // LongRunningRecognizeResponse { results: [] }
        });

        operation.on('progress', (metadata, apiResponse) => {
            console.log('progress', apiResponse)
        });

        operation.on('error', err => {
            throw (err);
        });
    })

1 个答案:

答案 0 :(得分:0)

const transcribeLong = async (url, channels) => {
    const nameExtract = url.split('/');
    const fileName = nameExtract[nameExtract.length - 1];
    let localfile;
    try {
        localfile = await download(url);
        fs.writeFileSync(fileName, localfile);
        await storage.bucket(BUCKET).upload(fileName);
        const audio = {
            uri: `gs://${BUCKET}/${fileName}`,
        };
        const request = {
            config: {
                languageCode: `en-US`,
                alternativeLanguageCodes: [`es-MX`, `en-US`],
                encoding: 'LINEAR16',
                sampleRateHertz: 8000,
                audioChannelCount: channels || 2, //changed from 2
                enableSeparateRecognitionPerChannel: true,
            },
            audio,
        };
        const [operation] = await client.longRunningRecognize(request);
        const [response] = await operation.promise();
        return response
    } catch (error) {
        console.error(error.toString());
    }
};

问题在请求中以错误的渠道作为参数。