idea pockettlnve怎么找快为,,。。。。。。。。。。。。。。。。。

Pocket|LOFTER(乐乎) - 记录生活,发现同好
LOFTER for ipad —— 记录生活,发现同好
记录生活,发现同好
51位喜爱 #Pocket 的小伙伴邀你来玩
查看高清大图
喜欢并收藏内容
关注达人获取动态
评论私信与同好交流
10秒注册,查看更多优质内容
网易公司版权所有 & ICP备:浙B2-增值电信业务经营许可证:浙B2-
{if x.type==1}
{if !!x.title}${x.title}{/if}
{if !!x.digest}${x.digest}{/if}
{if x.type==2}
{if x.type==3}
{if x.type==4}
加入 LOFTER 开通功能特权
查看高清大图
喜欢并收藏内容
关注达人获取动态
评论私信与同好交流19292人阅读
语音识别与TTS(12)
Linux(14)
嵌入式(17)
PocketSphinx语音识别系统的编程&&&&&& 关于语音识别的基础知识和sphinx的知识,具体可以参考我的另外的博文:语音识别的基础知识与CMUsphinx介绍:PocketSphinx语音识别系统的编译、安装和使用:PocketSphinx语音识别系统语言模型的训练和声学模型的改进:PocketSphinx语音识别系统声学模型的训练与使用&&&&&&&& 本文主要实现PocketSphinx语音识别系统的编程使用,主要分两个方面,一个是编程解码语音文件(主要参考CMU sphinx的wiki:),二是编程识别麦克风的语音(主要参考PocketSphinx源码包里的pocketsphinx.c文件)。对于后面加入我的人机交互系统的话,采用的是识别麦克风的语音的编程,具体使用时还需要对其进行精简。&一、编程解码语音文件1、编程:#include &pocketsphinx.h&
int main(int argc, char *argv[])
ps_decoder_t *
cmd_ln_t *
char const *hyp, *
int16 buf[512];
//1、初始化:创建一个配置对象 cmd_ln_t *
//cmd_ln_init函数第一个参数是我们需要更新的上一个配置,因为这里是初次创建,所以传入NULL;
//第二个参数是一个定义参数的数组,如果使用的是标准配置的参数集的话可以通过调用ps_args()去获得。
//第三个参数是是一个标志,它决定了参数的解释是否严格,如果为TRUE,那么遇到重复的或者未知的参
//数,将会导致解释失败;
//MODELDIR这个宏,指定了模型的路径,包括声学模型,语言模型和字典三个文件,是由gcc命令行传入,
//我们通过pkg-config工具从PocketSphinx的配置中去获得这个modeldir变量
config = cmd_ln_init(NULL, ps_args(), TRUE,
&-hmm&, MODELDIR &/hmm/en_US/hub4wsj_sc_8k&,
&-lm&, MODELDIR &/lm/en/turtle.DMP&,
&-dict&, MODELDIR &/lm/en/turtle.dic&,
if (config == NULL)
//2、初始化解码器(语言识别就是一个解码过程,通俗的将就是将你说的话解码成对应的文字串)
ps = ps_init(config);
if (ps == NULL)
//3、解码文件流
//因为音频输入接口(麦克风)受到一些特定平台的影响,不利用我们演示,所以我们通过解码音频文件流
//来演示PocketSphinx API的用法,goforward.raw是一个包含了一些诸如“go forward ten meters”等用来
//控制机器人的短语(指令)的音频文件,其在test/data/goforward.raw。把它复制到当前目录
fh = fopen(&/dev/input/event14&, &rb&);
if (fh == NULL) {
perror(&Failed to open goforward.raw&);
//4、使用ps_decode_raw()进行解码
rv = ps_decode_raw(ps, fh, NULL, -1);
if (rv & 0)
//5、得到解码的结果(概率最大的字串) hypothesis
hyp = ps_get_hyp(ps, &score, &uttid);
if (hyp == NULL)
printf(&Recognized: %s\n&, hyp);
//从内存中解码音频数据
//现在我们将再次解码相同的文件,但是使用API从内存块中解码音频数据。在这种情况下,首先我们
//需要使用ps_start_utt()开始说话:
fseek(fh, 0, SEEK_SET);
rv = ps_start_utt(ps, NULL);
if (rv & 0)
while (!feof(fh)) {
rv = ps_start_utt(ps, NULL);
if (rv & 0)
printf(&ready:\n&);
nsamp = fread(buf, 2, 512, fh);
printf(&read:\n&);
//我们将每次从文件中读取512大小的样本,使用ps_process_raw()把它们放到解码器中:
rv = ps_process_raw(ps, buf, nsamp, FALSE, FALSE);
printf(&process:\n&);
//我们需要使用ps_end_utt()去标记说话的结尾处:
rv = ps_end_utt(ps);
if (rv & 0)
//以相同精确的方式运行来检索假设的字符串:
hyp = ps_get_hyp(ps, &score, &uttid);
if (hyp == NULL)
printf(&Recognized: %s\n&, hyp);
//6、清理工作:使用ps_free()释放使用ps_init()返回的对象,不用释放配置对象。
fclose(fh);
ps_free(ps);
&&2、编译:编译方法:gcc -o test_ps test_ps.c \&&& -DMODELDIR=\&`pkg-config --variable=modeldir pocketsphinx`\& \&&& `pkg-config --cflags --libs pocketsphinx sphinxbase`//gcc的-D选项,指定宏定义,如-Dmacro=defn&&&相当于C语言中的#define macro=defn那么上面就表示在test_ps.c文件中,新加入一个宏定义:#define MODELDIR=\&`pkg-config --variable=modeldir pocketsphinx`\&\表示转义符,把“号转义。&&&&&&&& 这么做是为什么呢?因为程序中需要指定MODELDIR这个变量,但是因为不同的使用者,这个变量不一样,没办法指定死一个路径,所以只能放在编译时,让用户去根据自己的情况来指定。&pkg-config工具可以获得一个库的编译和连接等信息;#pkg-config --cflags --libs pocketsphinx sphinxbase显示:-I/usr/local/include/sphinxbase& -I/usr/local/include/pocketsphinx-L/usr/local/lib -lpocketsphinx -lsphinxbase –lsphinxad&#pkg-config --variable=modeldir pocketsphinx显示结果输出:/usr/local/share/pocketsphinx/model二、编程解码麦克风的录音1、编程&&&&&& 麦克风录音数据的获得主要是用sphinxbase封装了alsa的接口来实现。#include &stdio.h&
#include &string.h&
#include &sys/types.h&
#include &sys/time.h&
#include &signal.h&
#include &setjmp.h&
#include &sphinxbase/err.h&
//generic live audio interface for recording and playback
#include &sphinxbase/ad.h&
#include &sphinxbase/cont_ad.h&
#include &pocketsphinx.h&
static ps_decoder_t *
static cmd_ln_t *
static void print_word_times(int32 start)
ps_seg_t *iter = ps_seg_iter(ps, NULL);
while (iter != NULL)
int32 sf, ef,
ps_seg_frames (iter, &sf, &ef);
pprob = ps_seg_prob (iter, NULL, NULL, NULL);
conf = logmath_exp(ps_get_logmath(ps), pprob);
printf (&%s %f %f %f\n&, ps_seg_word (iter), (sf + start) / 100.0, (ef + start) / 100.0, conf);
iter = ps_seg_next (iter);
/* Sleep for specified msec */
static void sleep_msec(int32 ms)
tmo.tv_sec = 0;
tmo.tv_usec = ms * 1000;
select(0, NULL, NULL, NULL, &tmo);
* Main utterance processing loop:
for (;;) {
wait for sta
decode utterance until silence of at least 1
static void recognize_from_microphone()
ad_rec_t *
int16 adbuf[4096];
int32 k, ts,
char const *
char const *
cont_ad_t *
char word[256];
if ((ad = ad_open_dev(cmd_ln_str_r(config, &-adcdev&),
(int)cmd_ln_float32_r(config, &-samprate&))) == NULL)
E_FATAL(&Failed top open audio device\n&);
/* Initialize continuous listening module */
if ((cont = cont_ad_init(ad, ad_read)) == NULL)
E_FATAL(&Failed to initialize voice activity detection\n&);
if (ad_start_rec(ad) & 0)
E_FATAL(&Failed to start recording\n&);
if (cont_ad_calib(cont) & 0)
E_FATAL(&Failed to calibrate voice activity detection\n&);
for (;;) {
/* Indicate listening for next utterance */
printf(&READY....\n&);
fflush(stdout);
fflush(stderr);
/* Wait data for next utterance */
while ((k = cont_ad_read(cont, adbuf, 4096)) == 0)
sleep_msec(100);
if (k & 0)
E_FATAL(&Failed to read audio\n&);
* Non-zero amo start recognition of new utterance.
* NULL argument to uttproc_begin_utt =& automatic generation of utterance-id.
if (ps_start_utt(ps, NULL) & 0)
E_FATAL(&Failed to start utterance\n&);
ps_process_raw(ps, adbuf, k, FALSE, FALSE);
printf(&Listening...\n&);
fflush(stdout);
/* Note timestamp for this first block of data */
ts = cont-&read_
/* Decode utterance until end (marked by a &long& silence, &1sec) */
for (;;) {
/* Read non-silence audio data, if any, from continuous listening module */
if ((k = cont_ad_read(cont, adbuf, 4096)) & 0)
E_FATAL(&Failed to read audio\n&);
if (k == 0) {
* No s check current timestamp with most recent
* speech to see if more than 1 sec elapsed.
If so, end of utterance.
if ((cont-&read_ts - ts) & DEFAULT_SAMPLES_PER_SEC)
note current timestamp */
ts = cont-&read_
* Decode whatever data was read above.
rem = ps_process_raw(ps, adbuf, k, FALSE, FALSE);
/* If no work to be done, sleep a bit */
if ((rem == 0) && (k == 0))
sleep_msec(20);
* U flush any accumulated, unprocessed A/D data and stop
* listening until current utterance completely decoded
ad_stop_rec(ad);
while (ad_read(ad, adbuf, 4096) &= 0);
cont_ad_reset(cont);
printf(&Stopped listening, please wait...\n&);
fflush(stdout);
/* Finish decoding, obtain and print result */
ps_end_utt(ps);
hyp = ps_get_hyp(ps, NULL, &uttid);
printf(&%s: %s\n&, uttid, hyp);
fflush(stdout);
/* Exit if the first word spoken was GOODBYE */
if (hyp) {
sscanf(hyp, &%s&, word);
if (strcmp(word, &goodbye&) == 0)
/* Resume A/D recording for next utterance */
if (ad_start_rec(ad) & 0)
E_FATAL(&Failed to start recording\n&);
cont_ad_close(cont);
ad_close(ad);
static jmp_
static void sighandler(int signo)
longjmp(jbuf, 1);
int main(int argc, char *argv[])
config = cmd_ln_init(NULL, ps_args(), TRUE,
&-hmm&, MODELDIR &/hmm/en_US/hub4wsj_sc_8k&,
&-lm&, MODELDIR &/lm/en/turtle.DMP&,
&-dict&, MODELDIR &/lm/en/turtle.dic&,
if (config == NULL)
ps = ps_init(config);
if (ps == NULL)
signal(SIGINT, &sighandler);
if (setjmp(jbuf) == 0)
recognize_from_microphone();
ps_free(ps);
&2、编译和1.2一样。&&&&&&& 至于说后面把PocketSphinx语音识别系统加入我的人机交互系统这个阶段,因为感觉这个系统本身的识别率不是很高,自己做了适应和重新训练声学和语言模型后,提升还是有限,暂时实用性还不是很强,所以暂时搁置下,看能不能通过其他方法去改进目前的状态。希望有牛人指导下。另外,由于开学了,需要上课,所以后续的进程可能会稍微减慢,不过依然期待各位多多交流!呵呵&
参考知识库
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:6407625次
积分:26537
积分:26537
排名:第166名
原创:116篇
转载:11篇
评论:3524条
关注:机器学习、计算机视觉、人机交互和人工智能等领域。
交流请发邮件,不怎么看博客私信^-^
(4)(2)(1)(1)(2)(2)(1)(7)(5)(4)(4)(9)(2)(6)(1)(10)(5)(8)(14)(7)(8)(25)

我要回帖

更多关于 京东快递ve 的文章

 

随机推荐