【发布时间】:2020-04-29 13:01:33
【问题描述】:
我尝试使用 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}`);
【问题讨论】: