我尝试使用Google speech to text 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}`);发布于 2020-01-13 01:55:35
请检查您的网络连接速度(网速)
如果您的网络速度较慢,则整体响应时间会更长。
检查文件上传到google云的时间。
https://stackoverflow.com/questions/59706056
复制相似问题