-
大小: 4.77MB文件類(lèi)型: .zip金幣: 2下載: 0 次發(fā)布日期: 2023-08-11
- 語(yǔ)言: 其他
- 標(biāo)簽: 樹(shù)莓派??語(yǔ)音識(shí)別??
資源簡(jiǎn)介
離線語(yǔ)音識(shí)別,樹(shù)莓派語(yǔ)音識(shí)別科大訊飛語(yǔ)音識(shí)別離線包。

代碼片段和文件信息
/*
*?語(yǔ)音識(shí)別(Automatic?Speech?Recognition)技術(shù)能夠從語(yǔ)音中識(shí)別出特定的命令詞或語(yǔ)句模式。
*/
#include?
#include?
#include?
#include?
#include?“qisr.h“
#include?“msp_cmn.h“
#include?“msp_errors.h“
#define BUFFER_SIZE?2048
#define?HINTS_SIZE??100
#define?GRAMID_LEN 128
#define?frame_LEN 640?
?
int?get_grammar_id(char*?grammar_id?unsigned?int?id_len)
{
FILE* fp = NULL;
char* grammar = NULL;
unsigned?int grammar_len = 0;
unsigned?int read_len = 0;
const?char* ret_id = NULL;
unsigned?int ret_id_len = 0;
int ret = -1;
if?(NULL?==?grammar_id)
goto?grammar_exit;
fp?=?fopen(“gm_continuous_digit.abnf“?“rb“);
if?(NULL?==?fp)
{???
printf(“\nopen?grammar?file?failed!\n“);
goto?grammar_exit;
}
fseek(fp?0?SEEK_END);
grammar_len?=?ftell(fp);?//獲取語(yǔ)法文件大小?
fseek(fp?0?SEEK_SET);?
grammar?=?(char*)malloc(grammar_len?+?1);
if?(NULL?==?grammar)
{
printf(“\nout?of?memory!\n“);
goto?grammar_exit;
}
read_len?=?fread((void?*)grammar?1?grammar_len?fp);?//讀取語(yǔ)法內(nèi)容
if?(read_len?!=?grammar_len)
{
printf(“\nread?grammar?error!\n“);
goto?grammar_exit;
}
grammar[grammar_len]?=?‘\0‘;
ret_id?=?MSPUploadData(“usergram“?grammar?grammar_len?“dtt?=?abnf?sub?=?asr“?&ret);?//上傳語(yǔ)法
if?(MSP_SUCCESS?!=?ret)
{
printf(“\nMSPUploadData?failed?error?code:?%d.\n“?ret);
goto?grammar_exit;
}
ret_id_len?=?strlen(ret_id);
if?(ret_id_len?>=?id_len)
{
printf(“\nno?enough?buffer?for?grammar_id!\n“);
goto?grammar_exit;
}
strncpy(grammar_id?ret_id?ret_id_len);
printf(“grammar_id:?\“%s\“?\n“?grammar_id);?//下次可以直接使用該ID,不必重復(fù)上傳語(yǔ)法。
grammar_exit:
if?(NULL?!=?fp)
{
fclose(fp);
fp?=?NULL;
}
if?(NULL!=?grammar)
{
free(grammar);
grammar?=?NULL;
}
return?ret;
}
void?run_asr(const?char*?audio_file?const?char*?params?char*?grammar_id)
{
const?char* session_id =?NULL;
char rec_result[BUFFER_SIZE] ? =?{‘\0‘};
char hints[HINTS_SIZE] =?{‘\0‘};?//hints為結(jié)束本次會(huì)話的原因描述,由用戶(hù)自定義
unsigned?int total_len =?0;
int? aud_stat? =?MSP_AUDIO_SAMPLE_CONTINUE; //音頻狀態(tài)
int? ep_stat? =?MSP_EP_LOOKING_FOR_SPEECH; //端點(diǎn)檢測(cè)
int? rec_stat? =?MSP_REC_STATUS_SUCCESS; //識(shí)別狀態(tài)
int? errcode? =?MSP_SUCCESS;
FILE* f_pcm? =?NULL;
char* p_pcm? =?NULL;
long? pcm_count? =?0;
long? pcm_size? =?0;
long read_size =?0;
if?(NULL?==?audio_file)
goto?asr_exit;
f_pcm?=?fopen(audio_file?“rb“);
if?(NULL?==?f_pcm)?
{
printf(“\nopen?[%s]?failed!\n“?audio_file);
goto?asr_exit;
}
fseek(f_pcm?0?SEEK_END);
pcm_size?=?ftell(f_pcm);?//獲取音頻文件大小?
fseek(f_pcm?0?SEEK_SET);
p_pcm?=?(char*)malloc(pcm_size);
if?(NULL?==?p_pcm)
{
printf(“\nout?of?memory!\n“);
goto?asr_exit;
}
read_size?=?fread((void?*)p_pcm?1?pcm_size?f_pcm);?//讀取音頻文件內(nèi)容
if?(read_size?!=?pcm_size)
{
printf(“\nread?[%
?屬性????????????大小?????日期????時(shí)間???名稱(chēng)
-----------?---------??----------?-----??----
?????目錄???????????0??2016-06-17?21:35??Linux_voice_1.109\
?????文件????????1407??2015-11-23?14:40??Linux_voice_1.109\README.txt
?????目錄???????????0??2016-06-17?21:35??Linux_voice_1.109\bin\
?????文件?????????376??2015-09-17?20:33??Linux_voice_1.109\bin\gm_continuous_digit.abnf
?????目錄???????????0??2016-06-17?21:35??Linux_voice_1.109\bin\msc\
?????文件?????????743??2015-09-17?20:57??Linux_voice_1.109\bin\msc\msc.cfg
?????文件?????????242??2015-09-17?20:33??Linux_voice_1.109\bin\userwords.txt
?????目錄???????????0??2016-06-17?21:35??Linux_voice_1.109\bin\wav\
?????文件??????139442??2015-01-26?17:12??Linux_voice_1.109\bin\wav\iflytek01.wav
?????文件??????148220??2015-09-16?18:01??Linux_voice_1.109\bin\wav\iflytek02.wav
?????目錄???????????0??2016-06-17?21:35??Linux_voice_1.109\doc\
?????文件???????80978??2014-08-09?07:22??Linux_voice_1.109\doc\Grammar?Development?Guidelines.chm
?????文件??????755702??2015-07-19?22:13??Linux_voice_1.109\doc\MSC?Novice?Manual?for?Linux.pdf
?????文件?????2836511??2015-09-16?17:08??Linux_voice_1.109\doc\Open?Semantic?Platform?API?Documents.pdf
?????目錄???????????0??2016-06-17?21:35??Linux_voice_1.109\doc\iFlytek?MSC?Reference?Manual\
?????文件?????????246??2016-01-11?09:23??Linux_voice_1.109\doc\iFlytek?MSC?Reference?Manual\arrowdown.png
?????文件?????????229??2016-01-11?09:23??Linux_voice_1.109\doc\iFlytek?MSC?Reference?Manual\arrowright.png
?????文件?????????676??2016-01-11?09:23??Linux_voice_1.109\doc\iFlytek?MSC?Reference?Manual\bc_s.png
?????文件?????????147??2016-01-11?09:23??Linux_voice_1.109\doc\iFlytek?MSC?Reference?Manual\bdwn.png
?????文件?????????132??2016-01-11?09:23??Linux_voice_1.109\doc\iFlytek?MSC?Reference?Manual\closed.png
?????文件????????5113??2016-01-11?09:23??Linux_voice_1.109\doc\iFlytek?MSC?Reference?Manual\dir_aec8ed7db4e023b762de5ebd500ab794.html
?????文件?????????746??2016-01-11?09:23??Linux_voice_1.109\doc\iFlytek?MSC?Reference?Manual\doc.png
?????文件???????25493??2016-01-11?09:23??Linux_voice_1.109\doc\iFlytek?MSC?Reference?Manual\doxygen.css
?????文件????????3779??2016-01-11?09:23??Linux_voice_1.109\doc\iFlytek?MSC?Reference?Manual\doxygen.png
?????文件????????3140??2016-01-11?09:23??Linux_voice_1.109\doc\iFlytek?MSC?Reference?Manual\dynsections.js
?????文件????????5245??2016-01-11?09:23??Linux_voice_1.109\doc\iFlytek?MSC?Reference?Manual\files.html
?????文件?????????616??2016-01-11?09:23??Linux_voice_1.109\doc\iFlytek?MSC?Reference?Manual\folderclosed.png
?????文件?????????597??2016-01-11?09:23??Linux_voice_1.109\doc\iFlytek?MSC?Reference?Manual\folderopen.png
?????文件????????5494??2016-01-11?09:23??Linux_voice_1.109\doc\iFlytek?MSC?Reference?Manual\globals.html
?????文件????????5409??2016-01-11?09:23??Linux_voice_1.109\doc\iFlytek?MSC?Reference?Manual\globals_func.html
?????文件????????3443??2016-01-11?09:23??Linux_voice_1.109\doc\iFlytek?MSC?Reference?Manual\index.html
............此處省略76個(gè)文件信息
評(píng)論
共有 條評(píng)論