QT语音系统官方下载、配置与使用
QT语音系统是一款高效的语音识别、处理与合成软件,目前已经得到广泛应用。官方下载与配置非常简单,下面将详细介绍下载、配置与使用步骤。
一、QT语音系统官方下载
QT语音系统官方下载地址为:https://www.qtvoice.com/download.html,打开链接后会有三个版本供选择,分别是Windows、Linux和MacOS。根据自己的电脑系统选择相应版本的下载,点击即可开始下载。
下载完成后会生成一个压缩包,解压后即可得到一个名为“QT_Voice”的文件夹,这个文件夹里包括qt_voice.exe等重要文件以及配置文件。
二、QT语音系统的配置
1、打开QT_Voice文件夹,将qt_voice.exe程序复制到本地文件夹(例如:C:\\Software\\QT_Voice\\qt_voice.exe)。
2、打开windows终端,进入到qt_voice.exe所在目录,输入qt_voice --initconfig,即可开始配置工作。这个过程中要填写一些必要信息,如开发者账号、密码、appid等,配置完成后会得到一个秘钥文件。
3、将得到的秘钥文件放置在同一目录下,重命名为“license.json”。
至此,QT语音系统的配置工作已经完成,下面进入语音识别的应用场景。
三、QT语音系统的使用
1、启动终端,进入到qt_voice.exe所在目录,运行命令qt_voice,即可开启语音识别服务。
2、打开Windows自带的录音机,在录音机中选择麦克风作为输入设备,并录入你所要识别的语音语句。语句录制完成后,存储到本地的WAV格式文件中。
3、使用QT语音系统的识别功能,进行语音识别。示例代码如下:
```c++
#include
#include
#include
#include
#include
#include
#include \"asr_engine.h\"
#define MS_PER_SECOUND 1000
#define BUFFER_SAMPLES (16000/1000*20)
#define SAMPLES_PER_MS 16
#define MAX_RECORD_SIZE (300*1024) /* max record size in samples */
#define RECORD_PERIOD_MS 20
int main(int argc, char *argv[])
{
int err;
int card = -1;
int device = -1;
int rate = 16000;
int channels = 1;
snd_pcm_t *capture_handle;
snd_pcm_hw_params_t *hw_params;
snd_pcm_sw_params_t *sw_params;
char *buffer = NULL;
char *file_buffer = NULL;
unsigned int period = 20;
unsigned int buffer_frames = BUFFER_SAMPLES * channels;
unsigned int period_frames = period * rate * channels / MS_PER_SECOUND;
unsigned int filesize = 0;
snd_pcm_uframes_t frames, available_frames;
unsigned int count = 0;
std::string language = \"zh-cn\";
std::string category = \"general\";
std::string usage = \"recognition\";
if(argc > 2) {
card = atoi(argv[1]);
device = atoi(argv[2]);
}
err = asr_engine_init();
if(0 != err) {
std::cout << \"Init engine error, error code: \" << err << std::endl;
return 0;
}
if(card < 0 || device < 0) // Use default device
err = snd_pcm_open(&capture_handle, \"default\", SND_PCM_STREAM_CAPTURE, 0);
else
err = snd_pcm_open(&capture_handle, \"hw:card=\" + std::to_string(card) + \",device=\" + std::to_string(device), SND_PCM_STREAM_CAPTURE, 0);
if (err < 0) {
std::cout << \"Cannot open audio device \" << snd_strerror(err) << std::endl;
return 0;
}
snd_pcm_hw_params_alloca(&hw_params);
snd_pcm_hw_params_any(capture_handle, hw_params);
err = snd_pcm_hw_params_set_access(capture_handle, hw_params, SND_PCM_ACCESS_RW_INTERLEAVED);
if (err < 0) {
std::cout << \"Can't set interleaved mode \" << snd_strerror(err) << std::endl;
return 0;
}
err = snd_pcm_hw_params_set_format(capture_handle, hw_params, SND_PCM_FORMAT_S16_LE);
if (err < 0) {
std::cout << \"Can't set format \" << snd_strerror(err) << std::endl;
return 0;
}
err = snd_pcm_hw_params_set_channels_near(capture_handle, hw_params, &channels);
if (err < 0) {
std::cout << \"Can't set channels \" << snd_strerror(err) << std::endl;
return 0;
}
err = snd_pcm_hw_params_set_rate_near(capture_handle, hw_params, &rate, 0);
if (err < 0) {
std::cout << \"Can't set rate \" << snd_strerror(err) << std::endl;
return 0;
}
err = snd_pcm_hw_params_set_buffer_size(capture_handle, hw_params, buffer_frames);
if (err < 0) {
std::cout << \"Can't set buffer size \" << snd_strerror(err) << std::endl;
return 0;
}
err = snd_pcm_hw_params(capture_handle, hw_params);
if (err < 0) {
std::cout << \"Can't set hw params \" << snd_strerror(err) << std::endl;
return 0;
}
snd_pcm_sw_params_alloca(&sw_params);
snd_pcm_sw_params_current(capture_handle, sw_params);
err = snd_pcm_sw_params_set_avail_min(capture_handle, sw_params, period_frames);
if (err < 0) {
std::cout << \"Can't set avail min \" << snd_strerror(err) << std::endl;
return 0;
}
err = snd_pcm_sw_params_set_start_threshold(capture_handle, sw_params, buffer_frames - period_frames);
if (err < 0) {
std::cout << \"Can't set start threshold \" << snd_strerror(err) << std::endl;
return 0;
}
err = snd_pcm_sw_params_set_stop_threshold(capture_handle, sw_params, buffer_frames);
if (err < 0) {
std::cout << \"Can't set stop threshold \" << snd_strerror(err) << std::endl;
return 0;
}
err = snd_pcm_sw_params(capture_handle, sw_params);
if (err < 0) {
std::cout << \"Can't set sw params \" << snd_strerror(err) << std::endl;
return 0;
}
buffer = (char*)malloc(buffer_frames * 2);
file_buffer = (char*)malloc(MAX_RECORD_SIZE);
while(1) {
err = snd_pcm_wait(capture_handle, 1000);
if (err < 0)
break;
if(err == 0) {
count = 16384 / rate;
frames = 0;
while(frames < period_frames * count) {
err = snd_pcm_readi(capture_handle, buffer, period_frames);
if (err < 0) {
std::cout << \"read error: \" << snd_strerror(err) << std::endl;
break;
}
memcpy(file_buffer + filesize, buffer, period_frames * 2);
filesize += period_frames * 2;
frames += period_frames;
}
if(filesize > RECORD_PERIOD_MS * rate * channels / SAMPLES_PER_MS) {
std::cout << \"Start speech recognition\" << std::endl;
asr_engine_set_setting(common::SettingType::LANGUAGE, language);
asr_engine_set_setting(common::SettingType::CATEGORY, category);
asr_engine_set_setting(common::SettingType::USAGE, usage);
int text_size = 4096;
char *text = (char*)malloc(text_size);
err = asr_engine_speech_recognize(file_buffer, filesize, text, &text_size, NULL);
if (err == 0) {
std::cout << \"Recognization result: \" << text << std::endl;
} else {
std::cout << \"Recognization error, error code: \" << err << std::endl;
}
free(text);
filesize = 0;
}
}
}
snd_pcm_close(capture_handle);
free(buffer);
free(file_buffer);
return 0;
}
```
以上代码的主要作用是读取录音机的语音文件,调用QT语音系统的识别API进行语音识别,并返回语音识别的结果。其中,asr_engine_init()函数是用来初始化QT语音系统的。
恭喜您,经过以上步骤,您已经可以愉快地使用QT语音系统了!
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如有侵权请联系网站管理员删除,联系邮箱3237157959@qq.com。