作者 王振宇

道通u3s实时喊话增加降噪

@@ -681,7 +681,7 @@ void *getworkmodeTask(void *arg) @@ -681,7 +681,7 @@ void *getworkmodeTask(void *arg)
681 int i=0; 681 int i=0;
682 LOG_INFO("进入PSDK等待函数\n"); 682 LOG_INFO("进入PSDK等待函数\n");
683 T_UAVReturnCode returnCode; 683 T_UAVReturnCode returnCode;
684 - FILE * workModeFile = fopen("/root/work_mode.txt", "w"); 684 + FILE * workModeFile = fopen("/root/work_mode.txt", "wb");
685 while( i<15 && work_mode==0) 685 while( i<15 && work_mode==0)
686 { 686 {
687 LOG_INFO("wait {} work_mode={}.....\n",i,work_mode); 687 LOG_INFO("wait {} work_mode={}.....\n",i,work_mode);
@@ -68,28 +68,17 @@ echo "_____启动开始语音_____"; @@ -68,28 +68,17 @@ echo "_____启动开始语音_____";
68 chmod 777 H1start; 68 chmod 777 H1start;
69 ./H1start; 69 ./H1start;
70 70
71 -file_path="/root/work_mode.txt"  
72 ehco "____It_Just_Work____" 71 ehco "____It_Just_Work____"
73 while true; do 72 while true; do
74 echo "____开启 程序___" 73 echo "____开启 程序___"
75 chmod 777 CheckConnect.sh 74 chmod 777 CheckConnect.sh
76 ./CheckConnect.sh 75 ./CheckConnect.sh
77 76
78 - if [ -f "$file_path" ]; then  
79 - # 读取文件的第一行  
80 - value=$(head -n 1 "$file_path") 77 + echo "_____启动错误文件_____"
  78 + mount -o remount rw sdcard/
  79 + sync
81 80
82 - # 判断值是否等于1,1为sdk模式,在串口直连模式时,程序错误不喊话程序错误  
83 - if [ "$value" -eq 1 ]; then  
84 - echo "_____启动错误文件_____"  
85 - mount -o remount rw sdcard/  
86 - sync  
87 -  
88 - echo "____错误处理____"  
89 - chmod 777 H1error;  
90 - ./H1error;  
91 - fi  
92 -fi  
93 -  
94 - 81 + echo "____错误处理____"
  82 + chmod 777 H1error;
  83 + ./H1error;
95 done 84 done
@@ -12,7 +12,7 @@ if [ -f "$file_path" ]; then @@ -12,7 +12,7 @@ if [ -f "$file_path" ]; then
12 # 读取文件的第一行 12 # 读取文件的第一行
13 value=$(head -n 1 "$file_path") 13 value=$(head -n 1 "$file_path")
14 14
15 - # 判断值是否等于0 (0表示串口直连模式,1表示sdk模式) 15 + # 判断值是否等于0
16 if [ "$value" -eq 0 ]; then 16 if [ "$value" -eq 0 ]; then
17 chmod 777 JZ_UART_APP 17 chmod 777 JZ_UART_APP
18 ./JZ_UART_APP 18 ./JZ_UART_APP
@@ -13,6 +13,7 @@ @@ -13,6 +13,7 @@
13 #include "JZ_widget.h" 13 #include "JZ_widget.h"
14 #include "wiringPi.h" 14 #include "wiringPi.h"
15 #include "uav_widget.h" 15 #include "uav_widget.h"
  16 +#include <math.h>
16 17
17 int music_sum=0;//歌曲总数 18 int music_sum=0;//歌曲总数
18 int music_num=0;//当前播放的歌曲编号 19 int music_num=0;//当前播放的歌曲编号
@@ -733,10 +734,14 @@ int Opus_play(int8_t *cbits,int32_t len){//解码opus并播放 @@ -733,10 +734,14 @@ int Opus_play(int8_t *cbits,int32_t len){//解码opus并播放
733 Deinit_opus(); 734 Deinit_opus();
734 return EXIT_FAILURE; 735 return EXIT_FAILURE;
735 } 736 }
736 -  
737 - for (i = 0; i < WIDGET_SPEAKER_AUDIO_OPUS_CHANNELS * frame_size; i++) { //转换  
738 - pcm_bytes[2 * i] = out[i] & 0xFF;  
739 - pcm_bytes[2 * i + 1] = (out[i] >> 8) & 0xFF; 737 + opus_int16 TempPcm[WIDGET_SPEAKER_AUDIO_OPUS_MAX_FRAME_SIZE * WIDGET_SPEAKER_AUDIO_OPUS_CHANNELS];
  738 + for (i = 0; i < WIDGET_SPEAKER_AUDIO_OPUS_CHANNELS * frame_size; i++) { //转换
  739 +
  740 + TempPcm[i] = out[i] & 0xFF | (out[i] >> 8) << 8;
  741 + TempPcm[i] = PcmNoiseReduction(TempPcm[i]); //滤波
  742 +
  743 + pcm_bytes[2 * i] = TempPcm[i] & 0xFF;
  744 + pcm_bytes[2 * i + 1] = (TempPcm[i] >> 8) & 0xFF;
740 } 745 }
741 746
742 rawPlay(16000,pcm_bytes,frame_size*2);//播放音频 747 rawPlay(16000,pcm_bytes,frame_size*2);//播放音频
@@ -1194,4 +1199,27 @@ void SetRecordStatus(uint8_t status) @@ -1194,4 +1199,27 @@ void SetRecordStatus(uint8_t status)
1194 uint8_t GetRecordStatus(void) 1199 uint8_t GetRecordStatus(void)
1195 { 1200 {
1196 return aplay_flag; 1201 return aplay_flag;
  1202 +}
  1203 +
  1204 +/************************************
  1205 +*实时喊话降噪
  1206 +*函数名:PcmNoiseReduction
  1207 +*函数参数:
  1208 + @data:待处理数据
  1209 +*返回值:
  1210 + 处理好的数据
  1211 +*函数作者:wzy
  1212 +*************************************/
  1213 +#define NOISE_THRESHOLD 0.003 // 降噪阈值
  1214 +static short PcmNoiseReduction(short data)
  1215 +{
  1216 + // 转换为浮点数并进行降噪
  1217 + short re_data;
  1218 + float float_buffer = data / 32768.0f;
  1219 + if (fabs(float_buffer) < NOISE_THRESHOLD)
  1220 + {
  1221 + float_buffer = 0.0f; // 如果样本小于阈值,则将其置为零
  1222 + }
  1223 + re_data = (short)(float_buffer * 32767.0f); // 溢出处理
  1224 + return re_data;
1197 } 1225 }
@@ -46,7 +46,7 @@ void SetTtsStatus(uint8_t status);//设置文本喊话状态 @@ -46,7 +46,7 @@ void SetTtsStatus(uint8_t status);//设置文本喊话状态
46 uint8_t GetTtsStatus(void);//获取文本喊话状态 46 uint8_t GetTtsStatus(void);//获取文本喊话状态
47 void SetRecordStatus(uint8_t status);//设置录音喊话状态 47 void SetRecordStatus(uint8_t status);//设置录音喊话状态
48 uint8_t GetRecordStatus(void);//获取录音喊话状态 48 uint8_t GetRecordStatus(void);//获取录音喊话状态
49 - 49 +static short PcmNoiseReduction(short data);//实时喊话降噪算法
50 #ifdef __cplusplus 50 #ifdef __cplusplus
51 } 51 }
52 #endif 52 #endif