我尝试使用Google语音转换为文本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}`);
答案 0 :(得分:0)
请检查您的网络连接速度(互联网速度)
如果您的网络速度较慢,则总体响应时间将更长。
检查文件上传到Google云的时间。