当前位置: 首页 > news >正文

语音的前置处理(一)

语音的前置处理(一)

语音的前置处理(一)

1.简介

语音在采集和传输过程中,由于语音源的差异、信道的衰减、噪声的干扰以及远近效应,导致信号幅度相差很大。所有在语音处理之前我们需要对语音数据进行前置处理,包括预处理(AGCVAD、回音消除)、重采样和噪声抑制。

所有的代码都是基于speex开源库,具体内容可以参考http://speex.org/

本开发手册暂时只提供AGC的接口和测试代码,其他陆续添加进来。

2.接口说明

预处理模块包括自动增益控制、静音检测和回音消除。以下是接口函数,具体参考speex\ speex_preprocess.h

 

函数名称

功能简介

speex_preprocess_state_init

创建预处理器

speex_preprocess_state_destroy

销毁预处理器

speex_preprocess_run

处理一帧数据

speex_preprocess

处理一帧数据(废弃的)

speex_preprocess_estimate_update

更新预处理器

speex_preprocess_ctl

设置和读取预处理器的参数

 

2.1.1  speex_preprocess_state_init

函数原形

SpeexPreprocessState *speex_preprocess_state_init(int frame_sizeint sampling_rate);

功能

创建预处理器

参数

Frmae_size   [in]每帧的大小(建议帧长为20ms

Sample_rate  [in]采样率(支持8k16k44k

返回值

成功返回预处理器指针,失败返回NULL

说明

加入是16k的语音数据,帧长20ms等于320个采样

 

2.1.2  speex_preprocess_state_destroy

函数原形

void speex_preprocess_state_destroy(SpeexPreprocessState *st);

功能

销毁预处理器

参数

St           [in]处理器指针

返回值

Void

说明

 

 

2.1.3  speex_preprocess_run

函数原形

int speex_preprocess_run(SpeexPreprocessState *stspx_int16_t *x);

功能

处理一帧语音数据

参数

St           [in]处理器指针

X            [in|out]数据缓存,处理后的数据也存入该缓存中

返回值

如果VAD打开,返回值为1表示有语音,为0表示静音或者噪音

说明

 

 

2.1.4  speex_preprocess

函数原形

int speex_preprocess(SpeexPreprocessState *stspx_int16_t *xspx_int32_t *echo);

功能

处理一帧语音数据(废弃的函数,简介调用speex_preprocess_run

参数

St           [in]处理器指针

X            [in|out]数据缓存,处理后的数据也存入该缓存中     

返回值

 

说明

 

 

2.1.5  speex_preprocess_estimate_update

函数原形

void speex_preprocess_estimate_update(SpeexPreprocessState *stspx_int16_t *x);

功能

更新预处理器,不会计算输出语音

参数

St           [in]处理器指针

X            [in]数据缓存

返回值

Void

说明

 

 

2.1.6  speex_preprocess_ctl

函数原形

int speex_preprocess_ctl(SpeexPreprocessState *stint requestvoid *ptr);

功能

设置预处理器的参数

参数

St           [in]处理器指针

Request      [in]参数的类型(由宏来代表不同的参数)

Ptr          [in|out]参数的值(设置参数时为in,获得参数参数时为out,这个由宏决定)

返回值

成功返回0,失败返回-1(表明未知的请求参数)

说明

以下数标识参数类型的宏

/** Set preprocessor denoiser state */

#define SPEEX_PREPROCESS_SET_DENOISE 0

/** Get preprocessor denoiser state */

#define SPEEX_PREPROCESS_GET_DENOISE 1

 

/** Set preprocessor Automatic Gain Control state */

#define SPEEX_PREPROCESS_SET_AGC 2

/** Get preprocessor Automatic Gain Control state */

#define SPEEX_PREPROCESS_GET_AGC 3

 

/** Set preprocessor Voice Activity Detection state */

#define SPEEX_PREPROCESS_SET_VAD 4

/** Get preprocessor Voice Activity Detection state */

#define SPEEX_PREPROCESS_GET_VAD 5

 

/** Set preprocessor Automatic Gain Control level (float) */

#define SPEEX_PREPROCESS_SET_AGC_LEVEL 6

/** Get preprocessor Automatic Gain Control level (float) */

#define SPEEX_PREPROCESS_GET_AGC_LEVEL 7

 

/** Set preprocessor dereverb state */

#define SPEEX_PREPROCESS_SET_DEREVERB 8

/** Get preprocessor dereverb state */

#define SPEEX_PREPROCESS_GET_DEREVERB 9

 

/** Set preprocessor dereverb level */

#define SPEEX_PREPROCESS_SET_DEREVERB_LEVEL 10

/** Get preprocessor dereverb level */

#define SPEEX_PREPROCESS_GET_DEREVERB_LEVEL 11

 

/** Set preprocessor dereverb decay */

#define SPEEX_PREPROCESS_SET_DEREVERB_DECAY 12

/** Get preprocessor dereverb decay */

#define SPEEX_PREPROCESS_GET_DEREVERB_DECAY 13

 

/** Set probability required for the VAD to go from silence to voice */

#define SPEEX_PREPROCESS_SET_PROB_START 14

/** Get probability required for the VAD to go from silence to voice */

#define SPEEX_PREPROCESS_GET_PROB_START 15

 

/** Set probability required for the VAD to stay in the voice state (integer percent) */

#define SPEEX_PREPROCESS_SET_PROB_CONTINUE 16

/** Get probability required for the VAD to stay in the voice state (integer percent) */

#define SPEEX_PREPROCESS_GET_PROB_CONTINUE 17

 

/** Set maximum attenuation of the noise in dB (negative number) */

#define SPEEX_PREPROCESS_SET_NOISE_SUPPRESS 18

/** Get maximum attenuation of the noise in dB (negative number) */

#define SPEEX_PREPROCESS_GET_NOISE_SUPPRESS 19

 

/** Set maximum attenuation of the residual echo in dB (negative number) */

#define SPEEX_PREPROCESS_SET_ECHO_SUPPRESS 20

/** Get maximum attenuation of the residual echo in dB (negative number) */

#define SPEEX_PREPROCESS_GET_ECHO_SUPPRESS 21

 

/** Set maximum attenuation of the residual echo in dB when near end is active (negative number) */

#define SPEEX_PREPROCESS_SET_ECHO_SUPPRESS_ACTIVE 22

/** Get maximum attenuation of the residual echo in dB when near end is active (negative number) */

#define SPEEX_PREPROCESS_GET_ECHO_SUPPRESS_ACTIVE 23

 

/** Set the corresponding echo canceller state so that residual echo suppression can be performed (NULL for no residual echo suppression) */

#define SPEEX_PREPROCESS_SET_ECHO_STATE 24

/** Get the corresponding echo canceller state */

#define SPEEX_PREPROCESS_GET_ECHO_STATE 25

 

/** Set maximal gain increase in dB/second (int32) */

#define SPEEX_PREPROCESS_SET_AGC_INCREMENT 26

 

/** Get maximal gain increase in dB/second (int32) */

#define SPEEX_PREPROCESS_GET_AGC_INCREMENT 27

 

/** Set maximal gain decrease in dB/second (int32) */

#define SPEEX_PREPROCESS_SET_AGC_DECREMENT 28

 

/** Get maximal gain decrease in dB/second (int32) */

#define SPEEX_PREPROCESS_GET_AGC_DECREMENT 29

 

/** Set maximal gain in dB (int32) */

#define SPEEX_PREPROCESS_SET_AGC_MAX_GAIN 30

 

/** Get maximal gain in dB (int32) */

#define SPEEX_PREPROCESS_GET_AGC_MAX_GAIN 31

 

/*  Can't set loudness */

/** Get loudness */

#define SPEEX_PREPROCESS_GET_AGC_LOUDNESS 33

 

/*  Can't set gain */

/** Get current gain (int32 percent) */

#define SPEEX_PREPROCESS_GET_AGC_GAIN 35

 

/*  Can't set spectrum size */

/** Get spectrum size for power spectrum (int32) */

#define SPEEX_PREPROCESS_GET_PSD_SIZE 37

 

/*  Can't set power spectrum */

/** Get power spectrum (int32[] of squared values) */

#define SPEEX_PREPROCESS_GET_PSD 39

 

/*  Can't set noise size */

/** Get spectrum size for noise estimate (int32)  */

#define SPEEX_PREPROCESS_GET_NOISE_PSD_SIZE 41

 

/*  Can't set noise estimate */

/** Get noise estimate (int32[] of squared values) */

#define SPEEX_PREPROCESS_GET_NOISE_PSD 43

 

/* Can't set speech probability */

/** Get speech probability in last frame (int32).  */

#define SPEEX_PREPROCESS_GET_PROB 45

 

/** Set preprocessor Automatic Gain Control level (int32) */

#define SPEEX_PREPROCESS_SET_AGC_TARGET 46

/** Get preprocessor Automatic Gain Control level (int32) */

#define SPEEX_PREPROCESS_GET_AGC_TARGET 47

 

3.实例代码

3.1  AGC

#define NN 320

/*

    语音数据为单通道、16bit、16k

*/

int _tmain(int argc_TCHARargv[])

{

 

     short in[NN];

     int i;

     SpeexPreprocessState *st;

     int count=0;

     float f;

 

     st = speex_preprocess_state_init(NN, 16000);

    

     i=1;

     speex_preprocess_ctl(stSPEEX_PREPROCESS_SET_AGC, &i);

     f=16000;

     speex_preprocess_ctl(stSPEEX_PREPROCESS_SET_AGC_LEVEL, &f);

 

 

     while (1)

     {

         int vad;

         fread(insizeof(short), NNstdin);

         if (feof(stdin))

              break;

         vad = speex_preprocess_run(stin);

         //fprintf (stderr, "%d\n", vad);

         fwrite(insizeof(short), NNstdout);

         count++;

     }

     speex_preprocess_state_destroy(st);

 

     return 0;

}

posted on 2012-06-12 08:49 小小程序员001 阅读( ...) 评论( ...) 编辑 收藏

转载于:https://www.cnblogs.com/musicfans/archive/2012/06/12/2819317.html

相关文章:

  • 关于成都局2012年春运期间客票预售期调整的通知
  • 经典JavaScript正则表达式实战
  • [转载]给网游写一个挂吧(二) – 启动外挂上
  • 2012/6/19
  • Metro AppBarButtonStyles中按钮样式名称收集
  • [译]Kinect for Windows SDK开发入门(三):基础知识 下
  • 到底应该怎么样才能用上dropbox?
  • 优秀开发工具:推荐8个在线调试代码的网站
  • 应届生本人面试经历
  • IOS基本框架
  • sql 分割字符串
  • 六边形网格快速定位
  • OD调试实例1
  • Delphi GDI对象之绘制文本
  • [心得] phoneGap,doctor总结。重点是如何让页面自动跳转到settings bundle中用户设置的网址...
  • 2018天猫双11|这就是阿里云!不止有新技术,更有温暖的社会力量
  • docker python 配置
  • Flannel解读
  • HTML中设置input等文本框为不可操作
  • HTTP中GET与POST的区别 99%的错误认识
  • IndexedDB
  • IOS评论框不贴底(ios12新bug)
  • js学习笔记
  • Python_OOP
  • Redis提升并发能力 | 从0开始构建SpringCloud微服务(2)
  • SAP云平台运行环境Cloud Foundry和Neo的区别
  • Tornado学习笔记(1)
  • Vue组件定义
  • 搞机器学习要哪些技能
  • 聊聊springcloud的EurekaClientAutoConfiguration
  • 那些被忽略的 JavaScript 数组方法细节
  • 前端技术周刊 2019-01-14:客户端存储
  • 使用agvtool更改app version/build
  • 小程序上传图片到七牛云(支持多张上传,预览,删除)
  • 一个项目push到多个远程Git仓库
  • 职业生涯 一个六年开发经验的女程序员的心声。
  • linux 淘宝开源监控工具tsar
  • "无招胜有招"nbsp;史上最全的互…
  • # Maven错误Error executing Maven
  • #### go map 底层结构 ####
  • ###51单片机学习(2)-----如何通过C语言运用延时函数设计LED流水灯
  • #我与虚拟机的故事#连载20:周志明虚拟机第 3 版:到底值不值得买?
  • %@ page import=%的用法
  • (机器学习的矩阵)(向量、矩阵与多元线性回归)
  • (简单) HDU 2612 Find a way,BFS。
  • (九十四)函数和二维数组
  • (十八)三元表达式和列表解析
  • (一)80c52学习之旅-起始篇
  • (转)淘淘商城系列——使用Spring来管理Redis单机版和集群版
  • (自适应手机端)响应式新闻博客知识类pbootcms网站模板 自媒体运营博客网站源码下载
  • .apk 成为历史!
  • .NET 8.0 中有哪些新的变化?
  • .net core Swagger 过滤部分Api
  • .NET/C# 利用 Walterlv.WeakEvents 高性能地中转一个自定义的弱事件(可让任意 CLR 事件成为弱事件)
  • @ModelAttribute 注解