作者 王振宇

道通u3s实时喊话增加降噪

... ... @@ -681,7 +681,7 @@ void *getworkmodeTask(void *arg)
int i=0;
LOG_INFO("进入PSDK等待函数\n");
T_UAVReturnCode returnCode;
FILE * workModeFile = fopen("/root/work_mode.txt", "w");
FILE * workModeFile = fopen("/root/work_mode.txt", "wb");
while( i<15 && work_mode==0)
{
LOG_INFO("wait {} work_mode={}.....\n",i,work_mode);
... ...
... ... @@ -68,28 +68,17 @@ echo "_____启动开始语音_____";
chmod 777 H1start;
./H1start;
file_path="/root/work_mode.txt"
ehco "____It_Just_Work____"
while true; do
echo "____开启 程序___"
chmod 777 CheckConnect.sh
./CheckConnect.sh
if [ -f "$file_path" ]; then
# 读取文件的第一行
value=$(head -n 1 "$file_path")
echo "_____启动错误文件_____"
mount -o remount rw sdcard/
sync
# 判断值是否等于1,1为sdk模式,在串口直连模式时,程序错误不喊话程序错误
if [ "$value" -eq 1 ]; then
echo "_____启动错误文件_____"
mount -o remount rw sdcard/
sync
echo "____错误处理____"
chmod 777 H1error;
./H1error;
fi
fi
echo "____错误处理____"
chmod 777 H1error;
./H1error;
done
\ No newline at end of file
... ...
... ... @@ -12,7 +12,7 @@ if [ -f "$file_path" ]; then
# 读取文件的第一行
value=$(head -n 1 "$file_path")
# 判断值是否等于0 (0表示串口直连模式,1表示sdk模式)
# 判断值是否等于0
if [ "$value" -eq 0 ]; then
chmod 777 JZ_UART_APP
./JZ_UART_APP
... ...
... ... @@ -13,6 +13,7 @@
#include "JZ_widget.h"
#include "wiringPi.h"
#include "uav_widget.h"
#include <math.h>
int music_sum=0;//歌曲总数
int music_num=0;//当前播放的歌曲编号
... ... @@ -733,10 +734,14 @@ int Opus_play(int8_t *cbits,int32_t len){//解码opus并播放
Deinit_opus();
return EXIT_FAILURE;
}
for (i = 0; i < WIDGET_SPEAKER_AUDIO_OPUS_CHANNELS * frame_size; i++) { //转换
pcm_bytes[2 * i] = out[i] & 0xFF;
pcm_bytes[2 * i + 1] = (out[i] >> 8) & 0xFF;
opus_int16 TempPcm[WIDGET_SPEAKER_AUDIO_OPUS_MAX_FRAME_SIZE * WIDGET_SPEAKER_AUDIO_OPUS_CHANNELS];
for (i = 0; i < WIDGET_SPEAKER_AUDIO_OPUS_CHANNELS * frame_size; i++) { //转换
TempPcm[i] = out[i] & 0xFF | (out[i] >> 8) << 8;
TempPcm[i] = PcmNoiseReduction(TempPcm[i]); //滤波
pcm_bytes[2 * i] = TempPcm[i] & 0xFF;
pcm_bytes[2 * i + 1] = (TempPcm[i] >> 8) & 0xFF;
}
rawPlay(16000,pcm_bytes,frame_size*2);//播放音频
... ... @@ -1194,4 +1199,27 @@ void SetRecordStatus(uint8_t status)
uint8_t GetRecordStatus(void)
{
return aplay_flag;
}
/************************************
*实时喊话降噪
*函数名:PcmNoiseReduction
*函数参数:
@data:待处理数据
*返回值:
处理好的数据
*函数作者:wzy
*************************************/
#define NOISE_THRESHOLD 0.003 // 降噪阈值
static short PcmNoiseReduction(short data)
{
// 转换为浮点数并进行降噪
short re_data;
float float_buffer = data / 32768.0f;
if (fabs(float_buffer) < NOISE_THRESHOLD)
{
float_buffer = 0.0f; // 如果样本小于阈值,则将其置为零
}
re_data = (short)(float_buffer * 32767.0f); // 溢出处理
return re_data;
}
\ No newline at end of file
... ...
... ... @@ -46,7 +46,7 @@ void SetTtsStatus(uint8_t status);//设置文本喊话状态
uint8_t GetTtsStatus(void);//获取文本喊话状态
void SetRecordStatus(uint8_t status);//设置录音喊话状态
uint8_t GetRecordStatus(void);//获取录音喊话状态
static short PcmNoiseReduction(short data);//实时喊话降噪算法
#ifdef __cplusplus
}
#endif
... ...