谷歌语音到文本 API 延迟问题



我尝试使用谷歌语音到文本API将音频文件(WAV格式(转换为文本,并对响应时间进行了查询。下面是代码和响应持续时间。

音频文件约为 30kb,时长 3 秒。语音到文本服务大约需要 1.7 秒来转录,我认为这太高了,应该以毫秒为单位。这是正常的还是我缺少一些配置?

感谢任何建议。

const speech = require('@google-cloud/speech');
const fs = require('fs');
// Creates a client
const client = new speech.SpeechClient();
// The name of the audio file to transcribe
const fileName = 'xxx.wav';
// Reads a local audio file and converts it to base64
const file = fs.readFileSync(fileName);
const audioBytes = file.toString('base64');

// The audio file's encoding, sample rate in hertz, and BCP-47 language code
const audio = {
content: audioBytes,
};
const config = {
encoding: 'MULAW',
sampleRateHertz: 8000,
languageCode: 'en-GB',
model: 'default',
use_enhanced: 'true',
metadata: {InteractionType: 'VOICE_SEARCH',
microphoneDistance: 'NEARFIELD',
OriginalMediaType: 'AUDIO',
RecordingDeviceType: 'PHONE_LINE'},
};
const request = {
audio: audio,
config: config,
};
const [response] = await client.recognize(request);
const transcription = response.results
.map(result => result.alternatives[0].transcript)
.join('n');
console.log(`Transcription: ${transcription}`);

请检查您的网络连接速度(互联网速度(

如果您的网络速度会慢,整体响应时间会更长。

检查文件上传到谷歌云的时间。

最新更新