|
@@ -10,7 +10,7 @@ LEARN_REC_DEF learnAudio={NULL};
|
|
|
|
|
|
typedef struct{
|
|
typedef struct{
|
|
unsigned short maxVolume;//最大音量
|
|
unsigned short maxVolume;//最大音量
|
|
- unsigned short avSpeed;//录音平均语速
|
|
|
|
|
|
+ float avSpeed;//录音平均语速
|
|
int64_t time;//记录录音时长
|
|
int64_t time;//记录录音时长
|
|
unsigned char charactorNum;//单词个数
|
|
unsigned char charactorNum;//单词个数
|
|
}LEARN_REC_RESULT_DEF;//录音结果
|
|
}LEARN_REC_RESULT_DEF;//录音结果
|
|
@@ -27,20 +27,26 @@ static void initRecResult(unsigned char charaNum){
|
|
recordResult.charactorNum=charaNum;
|
|
recordResult.charactorNum=charaNum;
|
|
}
|
|
}
|
|
static void recordResultMake(void){
|
|
static void recordResultMake(void){
|
|
- int64_t time=nwy_get_ms();
|
|
|
|
- time = (time-recordResult.time)/1000;
|
|
|
|
|
|
+ int64_t time;
|
|
|
|
+ float tmp;
|
|
|
|
+ time=nwy_get_ms();
|
|
|
|
+ time = time-recordResult.time;
|
|
if(time<1) time=1;//最小为1秒
|
|
if(time<1) time=1;//最小为1秒
|
|
- recordResult.avSpeed = recordResult.charactorNum/time;//单词/秒
|
|
|
|
- MSG_INFO(1, "Chara speed:%d,%d", recordResult.avSpeed, time);
|
|
|
|
|
|
+ tmp=recordResult.charactorNum;
|
|
|
|
+ recordResult.avSpeed = 1000*tmp/time;//单词/秒
|
|
|
|
+ MSG_INFO(1, "Chara speed:%.1f,num:%d,t:%lldms", recordResult.avSpeed, recordResult.charactorNum,time);
|
|
}
|
|
}
|
|
/*获取本次录音过程中的最大音量值*/
|
|
/*获取本次录音过程中的最大音量值*/
|
|
unsigned short learnGetRecordMaxVolume(void){
|
|
unsigned short learnGetRecordMaxVolume(void){
|
|
//return (recordResult.maxVolume*LEV_NUM/0x7FFF);
|
|
//return (recordResult.maxVolume*LEV_NUM/0x7FFF);
|
|
return recordResult.maxVolume;
|
|
return recordResult.maxVolume;
|
|
}
|
|
}
|
|
|
|
+#define SPEED_FACTOR 4
|
|
/*获取本次录音的语速:单词/秒*/
|
|
/*获取本次录音的语速:单词/秒*/
|
|
-unsigned char learnGetRecordRecSpeed(void){
|
|
|
|
- return recordResult.avSpeed;
|
|
|
|
|
|
+float learnGetRecordRecSpeed(void){
|
|
|
|
+ float speedscore=getLearnSpeedParam()*recordResult.avSpeed*SPEED_FACTOR;
|
|
|
|
+ if(speedscore>10) speedscore=10;
|
|
|
|
+ return speedscore;
|
|
}
|
|
}
|
|
bool learnStartRecord(unsigned char charaNum){
|
|
bool learnStartRecord(unsigned char charaNum){
|
|
//初始化编码器
|
|
//初始化编码器
|
|
@@ -218,68 +224,69 @@ static int recordDataCb(unsigned char *pcm, unsigned int len){
|
|
return 0;
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+#ifdef SAVE_PCM_SD
|
|
|
|
+int sdFd=-1;
|
|
|
|
+void pcmFileOpen(void){
|
|
|
|
+ int fd;
|
|
|
|
+ char file[50];
|
|
|
|
+ if(sdFd>0) return;
|
|
|
|
+ snprintf(file, sizeof(file), "%s/pcm_low.rec", SD_TOKEN);
|
|
|
|
+ fd = nwy_sdk_fopen(file, NWY_CREAT | NWY_RDWR|NWY_TRUNC);//清0式
|
|
|
|
+ if(fd<0){
|
|
|
|
+ MSG_INFO(1,"open failed");
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ sdFd=fd;
|
|
|
|
+ MSG_INFO(1,"open ok");
|
|
|
|
+}
|
|
|
|
+void pcmFileClose(void){
|
|
|
|
+ if(sdFd<0){
|
|
|
|
+ MSG_INFO(1,"no need close");
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ nwy_sdk_fclose(sdFd);
|
|
|
|
+ MSG_INFO(1,"close ok");
|
|
|
|
+ sdFd=-1;
|
|
|
|
+}
|
|
|
|
+void pcmSaveData(unsigned char *pcm, int len){
|
|
|
|
+ if(sdFd<0){
|
|
|
|
+ MSG_INFO(1,"not open");
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ nwy_sdk_fwrite(sdFd, pcm, len);
|
|
|
|
+}
|
|
|
|
+#endif
|
|
static void pcmVolProcess(unsigned char *pcm, unsigned int len){
|
|
static void pcmVolProcess(unsigned char *pcm, unsigned int len){
|
|
-#if 0
|
|
|
|
|
|
+#ifdef SAVE_PCM_SD
|
|
|
|
+ pcmSaveData(pcm,len);
|
|
|
|
+#else
|
|
//对语音数据进行平均音量分析,分析方法为累加,并求平均值,静音时是为0的值
|
|
//对语音数据进行平均音量分析,分析方法为累加,并求平均值,静音时是为0的值
|
|
#define VOL_SUM_FRAME 5
|
|
#define VOL_SUM_FRAME 5
|
|
#define VOL_SHORT_LEV (VOL_SUM_FRAME*160)
|
|
#define VOL_SHORT_LEV (VOL_SUM_FRAME*160)
|
|
- static unsigned int pcmSum=0;
|
|
|
|
- unsigned short tmp;
|
|
|
|
- unsigned int i;
|
|
|
|
- unsigned int tVol;
|
|
|
|
|
|
+ short *ptr=(short *)pcm;
|
|
|
|
+ int i;
|
|
static unsigned short frameVolNum=0;
|
|
static unsigned short frameVolNum=0;
|
|
- unsigned int sum=0;
|
|
|
|
-
|
|
|
|
|
|
+ unsigned int sum=0,tmp;
|
|
|
|
+ static unsigned int pcmSum=0;
|
|
|
|
+ //char info[60];
|
|
if(len != 320) return;
|
|
if(len != 320) return;
|
|
for(i=0;i<160;i++){
|
|
for(i=0;i<160;i++){
|
|
- tmp=pcm[2*i+1];//&0x7F;//取绝对值
|
|
|
|
- tmp <<= 8;
|
|
|
|
- tmp |= pcm[2*i];
|
|
|
|
|
|
+ tmp=abs(ptr[i]);
|
|
pcmSum += tmp;
|
|
pcmSum += tmp;
|
|
- sum += tmp;
|
|
|
|
}
|
|
}
|
|
- sum /= 160;
|
|
|
|
- if(sum > recordResult.maxVolume) recordResult.maxVolume=sum;//计算每一帧的最大音量
|
|
|
|
- if(++frameVolNum>=VOL_SUM_FRAME){//1秒得出一个平均音量吧
|
|
|
|
- tVol=pcmSum/VOL_SHORT_LEV;
|
|
|
|
- tVol *= LEV_NUM;
|
|
|
|
- tVol /= 0xfFFF;
|
|
|
|
- //MSG_INFO(1, "***%d,%d,%d", pcmSum,VOL_SHORT_LEV,tVol);
|
|
|
|
- learnRecSetVol(tVol);
|
|
|
|
|
|
+ if(++frameVolNum>=VOL_SUM_FRAME){
|
|
|
|
+ sum=pcmSum/VOL_SHORT_LEV;
|
|
|
|
+ //snprintf(info, sizeof(info), "[0]{%d}",sum);
|
|
|
|
+ //nwy_usb_serial_send(info, strlen(info));
|
|
|
|
+ //MSG_INFO(1, "pcm:%d", sum);
|
|
|
|
+ sum *= (LEV_NUM-1);
|
|
|
|
+ sum /=10000;
|
|
|
|
+ if(sum >(LEV_NUM-1)) sum = LEV_NUM-1;
|
|
|
|
+ learnRecSetVol(sum);
|
|
|
|
+ if(sum > recordResult.maxVolume) recordResult.maxVolume=sum;//计算每一帧的最大音量
|
|
pcmSum=0;
|
|
pcmSum=0;
|
|
frameVolNum=0;
|
|
frameVolNum=0;
|
|
}
|
|
}
|
|
-#else
|
|
|
|
- const unsigned short vtable[]={
|
|
|
|
- 30000,
|
|
|
|
- 30000+1500,
|
|
|
|
- 30000+1500*2,
|
|
|
|
- 30000+1500*3,
|
|
|
|
- 30000+1500*4,
|
|
|
|
- 30000+1500*5,
|
|
|
|
- 30000+1500*6,
|
|
|
|
- 30000+1500*7,
|
|
|
|
- 30000+1500*8,
|
|
|
|
- 30000+1500*9,
|
|
|
|
- 30000+1500*10,
|
|
|
|
- };
|
|
|
|
- int i,tmp;
|
|
|
|
- unsigned int sum=0,avrPcm,max=0;
|
|
|
|
- if(len != 320) return;
|
|
|
|
- for(i=0;i<len;i+=2){//求得一帧语音总量
|
|
|
|
- tmp=pcm[i+1];
|
|
|
|
- tmp <<= 8;
|
|
|
|
- tmp &= 0xff00;
|
|
|
|
- tmp |= pcm[i];
|
|
|
|
- avrPcm = abs(tmp);
|
|
|
|
- sum += avrPcm;
|
|
|
|
- }
|
|
|
|
- sum /= 160;
|
|
|
|
- for(i=0;i<11;i++){
|
|
|
|
- if(sum<vtable[i]) break;
|
|
|
|
- }
|
|
|
|
- learnRecSetVol(i);
|
|
|
|
- if(i > recordResult.maxVolume) recordResult.maxVolume=i;
|
|
|
|
#endif
|
|
#endif
|
|
}
|
|
}
|
|
|
|
|