Speex的使用

article/2025/10/8 2:19:16
Speex: a free codec for free speech
Downloads

Speex是一套主要针对语音的开源免费,无专利保护的音频压缩格式。Speex工程着力于通过提供一个可以替代高性能语音编解码来降低语音应用输入门槛 。另外,相对于其它编解码器,Speex也很适合网络应用,在网络应用上有着自己独特的优势。同时,Speex还是GNU工程的一部分,在改版的BSD协议中得到了很好的支持。




The latest development version of Speex is always available through Git by at http://git.xiph.org/speex.git. Note that packaging information for Debian can be found on the packages page. In addition, RareWares maintains useful Windows utilities such as SpeexDrop.

Current Unstable Release (recommended)

1.2rc1

This release adds support for acoustic echo cancellation with multiple microphones and multiple loudspeakers. It also adds an API to decorrelate loudspeaker signals to improve multi-channel performance. In the bugfix department, there are fixes for a few bugs in the echo canceller, jitter buffer and preprocessor. At this point, the API for 1.2 should be stable and only a few very minor additions are planned.

Downloads:
  • Source Code

1.2beta3

The most obvious change in this release is that all the non-codec components (preprocessor, echo cancellation, jitter buffer) have been moved to a new libspeexdsp library. Other changes include a new jitter buffer algorithm and resampler improvements/fixes. This is also the first release where libspeex can be built without any floating point support. To do this, the float compatibility API must be disabled (--disable-float-api or DISABLE_FLOAT_API) and the VBR feature must be disabled (--disable-vbr or DISABLE_VBR).

Downloads:
  • Source Code
  • Windows binaries

1.2beta2

Again, this new releases brings many improvements. The RAM requirement for wideband has gone down drastically (i.e. more than 2x). A new resampler module has been added, providing arbitrary sampling rate conversion -- fast. The echo canceller has also been improved. A bug in 1.2beta1 that made the echo canceller unstable has been fixed. The echo canceller should now converge faster, be robust and tolerant of incorrect capture-playback synchronisation. The preprocessor has also been greatly improved. Not only should the quality be better, but it is now fully converted to fixed-point. At last, early TriMedia support (incomplete) has been merged.

Downloads:
  • Source Code
  • i386 RPM
  • i386 Development RPM
  • Source RPM
  • No Windows binaries -- looking for a maintainer

Current Stable Release (old, not recommended)

1.0.5

The main change with this release is that it includes API additions from the 1.1.x branch (while being backward compatible), so that transition from 1.0.x to 1.1.x can be made easier.

  • Source Code
  • i386 RPM
  • i386 Development RPM
  • Source RPM
  • Windows binaries (1.0.4)

DirectShow Filters

If you just want to listen to Speex files in Windows Media Player, get Xiph.Org's DirectShow Filters for Speex.




http://blog.csdn.net/chenfeng0104/article/details/7088138

在Android开发中,需要录音并发送到对方设备上。这时问题来了,手机常会是GPRS、3G等方式上网,所以节省流量是非常关键的,使用Speex来压缩音频文件,可以将音频压文件小数倍。

1.去Speex官网下载最新Speex源码。

2.创建一个新的应用(我创建的应用名为Audio),并创建一个jni目录($project/jni)。

3.把speex源码目录下的libspeex和include目录及其子目录文件全部拷贝到$project/jni目录下($project/jni/libspeex and $project/jni/include)。

4.在jni目录下新增Android.mk文件,编辑内容如下

[plain]  view plain copy
  1. LOCAL_PATH := $(call my-dir)  
  2.   
  3.   
  4. include $(CLEAR_VARS)  
  5.    
  6. LOCAL_MODULE    := libspeex  
  7. LOCAL_CFLAGS = -DFIXED_POINT -DUSE_KISS_FFT -DEXPORT="" -UHAVE_CONFIG_H  
  8. LOCAL_C_INCLUDES := $(LOCAL_PATH)/include  
  9.    
  10. LOCAL_SRC_FILES :=  \  
  11. ./speex_jni.cpp \  
  12. ./libspeex/bits.c \  
  13. ./libspeex/buffer.c \  
  14. ./libspeex/cb_search.c \  
  15. ./libspeex/exc_10_16_table.c \  
  16. ./libspeex/exc_10_32_table.c \  
  17. ./libspeex/exc_20_32_table.c \  
  18. ./libspeex/exc_5_256_table.c \  
  19. ./libspeex/exc_5_64_table.c \  
  20. ./libspeex/exc_8_128_table.c \  
  21. ./libspeex/fftwrap.c \  
  22. ./libspeex/filterbank.c \  
  23. ./libspeex/filters.c \  
  24. ./libspeex/gain_table.c \  
  25. ./libspeex/gain_table_lbr.c \  
  26. ./libspeex/hexc_10_32_table.c \  
  27. ./libspeex/hexc_table.c \  
  28. ./libspeex/high_lsp_tables.c \  
  29. ./libspeex/jitter.c \  
  30. ./libspeex/kiss_fft.c \  
  31. ./libspeex/kiss_fftr.c \  
  32. ./libspeex/lpc.c \  
  33. ./libspeex/lsp.c \  
  34. ./libspeex/lsp_tables_nb.c \  
  35. ./libspeex/ltp.c \  
  36. ./libspeex/mdf.c \  
  37. ./libspeex/modes.c \  
  38. ./libspeex/modes_wb.c \  
  39. ./libspeex/nb_celp.c \  
  40. ./libspeex/preprocess.c \  
  41. ./libspeex/quant_lsp.c \  
  42. ./libspeex/resample.c \  
  43. ./libspeex/sb_celp.c \  
  44. ./libspeex/scal.c \  
  45. ./libspeex/smallft.c \  
  46. ./libspeex/speex.c \  
  47. ./libspeex/speex_callbacks.c \  
  48. ./libspeex/speex_header.c \  
  49. ./libspeex/stereo.c \  
  50. ./libspeex/vbr.c \  
  51. ./libspeex/vq.c \  
  52. ./libspeex/window.c  
  53.    
  54. include $(BUILD_SHARED_LIBRARY)  

5. 在jni目录下新增Application.mk文件,编辑内容如下

[plain]  view plain copy
  1. APP_ABI := armeabi armeabi-v7a  

6.在 $project/jni/include/speex/目录下新增speex_config_types.h文件,编辑内容如下

[cpp]  view plain copy
  1. #ifndef __SPEEX_TYPES_H__  
  2. #define __SPEEX_TYPES_H__  
  3. typedef short spx_int16_t;  
  4. typedef unsigned short spx_uint16_t;  
  5. typedef int spx_int32_t;  
  6. typedef unsigned int spx_uint32_t;  
  7. #endif  

7.创建JNI包装类speex_jni.cpp,用来调用Speex中的C代码函数,编辑内容如下

[cpp]  view plain copy
  1. #include <jni.h>  
  2.   
  3. #include <string.h>  
  4. #include <unistd.h>  
  5.   
  6. #include <speex/speex.h>  
  7.   
  8. static int codec_open = 0;  
  9.   
  10. static int dec_frame_size;  
  11. static int enc_frame_size;  
  12.   
  13. static SpeexBits ebits, dbits;  
  14. void *enc_state;  
  15. void *dec_state;  
  16.   
  17. static JavaVM *gJavaVM;  
  18.   
  19. extern "C"  
  20. JNIEXPORT jint JNICALL Java_com_audio_Speex_open  
  21.   (JNIEnv *env, jobject obj, jint compression) {  
  22.     int tmp;  
  23.   
  24.     if (codec_open++ != 0)  
  25.         return (jint)0;  
  26.   
  27.     speex_bits_init(&ebits);  
  28.     speex_bits_init(&dbits);  
  29.   
  30.     enc_state = speex_encoder_init(&speex_nb_mode);  
  31.     dec_state = speex_decoder_init(&speex_nb_mode);  
  32.     tmp = compression;  
  33.     speex_encoder_ctl(enc_state, SPEEX_SET_QUALITY, &tmp);  
  34.     speex_encoder_ctl(enc_state, SPEEX_GET_FRAME_SIZE, &enc_frame_size);  
  35.     speex_decoder_ctl(dec_state, SPEEX_GET_FRAME_SIZE, &dec_frame_size);  
  36.   
  37.     return (jint)0;  
  38. }  
  39.   
  40. extern "C"  
  41. JNIEXPORT jint Java_com_audio_Speex_encode  
  42.     (JNIEnv *env, jobject obj, jshortArray lin, jint offset, jbyteArray encoded, jint size) {  
  43.   
  44.         jshort buffer[enc_frame_size];  
  45.         jbyte output_buffer[enc_frame_size];  
  46.     int nsamples = (size-1)/enc_frame_size + 1;  
  47.     int i, tot_bytes = 0;  
  48.   
  49.     if (!codec_open)  
  50.         return 0;  
  51.   
  52.     speex_bits_reset(&ebits);  
  53.   
  54.     for (i = 0; i < nsamples; i++) {  
  55.         env->GetShortArrayRegion(lin, offset + i*enc_frame_size, enc_frame_size, buffer);  
  56.         speex_encode_int(enc_state, buffer, &ebits);  
  57.     }  
  58.     //env->GetShortArrayRegion(lin, offset, enc_frame_size, buffer);  
  59.     //speex_encode_int(enc_state, buffer, &ebits);  
  60.   
  61.     tot_bytes = speex_bits_write(&ebits, (char *)output_buffer,  
  62.                      enc_frame_size);  
  63.     env->SetByteArrayRegion(encoded, 0, tot_bytes,  
  64.                 output_buffer);  
  65.   
  66.         return (jint)tot_bytes;  
  67. }  
  68.   
  69. extern "C"  
  70. JNIEXPORT jint JNICALL Java_com_audio_Speex_decode  
  71.     (JNIEnv *env, jobject obj, jbyteArray encoded, jshortArray lin, jint size) {  
  72.   
  73.         jbyte buffer[dec_frame_size];  
  74.         jshort output_buffer[dec_frame_size];  
  75.         jsize encoded_length = size;  
  76.   
  77.     if (!codec_open)  
  78.         return 0;  
  79.   
  80.     env->GetByteArrayRegion(encoded, 0, encoded_length, buffer);  
  81.     speex_bits_read_from(&dbits, (char *)buffer, encoded_length);  
  82.     speex_decode_int(dec_state, &dbits, output_buffer);  
  83.     env->SetShortArrayRegion(lin, 0, dec_frame_size,  
  84.                  output_buffer);  
  85.   
  86.     return (jint)dec_frame_size;  
  87. }  
  88.   
  89. extern "C"  
  90. JNIEXPORT jint JNICALL Java_com_audio_getFrameSize  
  91.     (JNIEnv *env, jobject obj) {  
  92.   
  93.     if (!codec_open)  
  94.         return 0;  
  95.     return (jint)enc_frame_size;  
  96.   
  97. }  
  98.   
  99. extern "C"  
  100. JNIEXPORT void JNICALL Java_com_audio_Speex_close  
  101.     (JNIEnv *env, jobject obj) {  
  102.   
  103.     if (--codec_open != 0)  
  104.         return;  
  105.   
  106.     speex_bits_destroy(&ebits);  
  107.     speex_bits_destroy(&dbits);  
  108.     speex_decoder_destroy(dec_state);  
  109.     speex_encoder_destroy(enc_state);  
  110. }  

8.在Java层创建Speex工具类,内容如下

[java]  view plain copy
  1. package com.audio;  
  2.   
  3. class Speex  {  
  4.   
  5.     /* quality 
  6.      * 1 : 4kbps (very noticeable artifacts, usually intelligible) 
  7.      * 2 : 6kbps (very noticeable artifacts, good intelligibility) 
  8.      * 4 : 8kbps (noticeable artifacts sometimes) 
  9.      * 6 : 11kpbs (artifacts usually only noticeable with headphones) 
  10.      * 8 : 15kbps (artifacts not usually noticeable) 
  11.      */  
  12.     private static final int DEFAULT_COMPRESSION = 8;  
  13.   
  14.     Speex() {  
  15.     }  
  16.   
  17.     public void init() {  
  18.         load();   
  19.         open(DEFAULT_COMPRESSION);  
  20.     }  
  21.       
  22.     private void load() {  
  23.         try {  
  24.             System.loadLibrary("speex");  
  25.         } catch (Throwable e) {  
  26.             e.printStackTrace();  
  27.         }  
  28.   
  29.     }  
  30.   
  31.     public native int open(int compression);  
  32.     public native int getFrameSize();  
  33.     public native int decode(byte encoded[], short lin[], int size);  
  34.     public native int encode(short lin[], int offset, byte encoded[], int size);  
  35.     public native void close();  
  36.       
  37. }  

9.打开cygwin工具,切换到项目目录(我项目是在F:\workspace\Audio),输入$NDK/ndk-build

cygwin工具的安装与配置,可以看这篇文章——使用NDK与环境搭建


会在项目中生成libs目录和libspeex.so文件,这就是Speex类中System.loadLibrary("speex");代码引用的,系统会根据操作系统由"speex"找到对应的动态库libspeex.so,Windows下是.dll文件,linux下是.so文件。

当前,我的项目结构如下图



可以从android-recorder下载代码作为参考



http://chatgpt.dhexx.cn/article/2KHkY82y.shtml

相关文章

网络测速服务器OpenSpeedTest

什么是 OpenSpeedTest &#xff1f; OpenSpeedTest 是一个跨平台的互联网速度测试应用程序。因此&#xff0c;您可以在不同操作系统中的各种网络浏览器中测试您的互联网速度&#xff0c;而无需安装任何其他应用程序或插件&#xff08;无需 Flash 或 Java&#xff09;。这意味着…

【SpeechX—统一高性能语音部署工具】SpeechX Custom ASR

(以下内容搬运自 PaddleSpeech) 在一些场景中&#xff0c;识别系统需要高精度的识别一些稀有词&#xff0c;例如导航软件中地名识别。而通过定制化识别可以满足这一需求。 相关demo: https://github.com/PaddlePaddle/PaddleSpeech/tree/develop/demos/custom_streaming_asr …

Speex for Android

http://blog.csdn.net/chenfeng0104/article/details/7088138 在Android开发中&#xff0c;需要录音并发送到对方设备上。这时问题来了&#xff0c;手机常会是GPRS、3G等方式上网&#xff0c;所以节省流量是非常关键的&#xff0c;使用Speex来压缩音频文件&#xff0c;可以将音…

IOS开发之SDWebImage

SDWebImage 前言&#xff1a;在我们日常的开发中我们通常会使用SDWebImage来实现UIImageView加载来自互联网的远程图片 官方介绍&#xff1a;一个具有缓存支持的异步映像下载程序 功能简介 一个添加了web图片加载和缓存管理的UIImageView分类一个异步图片下载器一个异步的内存…

SDWebImage-解码、压缩图像

一、简单介绍 研究了下SDWebImage的源码&#xff0c;借鉴了别人的一些资料&#xff0c;感觉逐渐的明白的一些原理&#xff0c;现在就来记录下。 在我们使用 UIImage 的时候&#xff0c;创建的图片通常不会直接加载到内存&#xff0c;而是在渲染的时候默认在主线程上再进行解码…

sdwebimage 加载webp图片

sdwebimage加载 webp / git 配置宏 - (void)setUpCusPhoto {_scrollView [UIScrollView new];_scrollView.frame self.view.bounds;[self.view addSubview:_scrollView];//webpUIImageView *view [[UIImageView alloc] init];view.frame CGRectMake(10, 100, 320, 200);NS…

SDWebImage 5.0简介

一、 SDWebImage原理简介 1.结构 (设计思路借鉴&#xff1a;提供多种接口&#xff0c;到底层调用到同一个方法&#xff0c;减少调用方对可选参数的传递) UIImageViewWebCache和UIButtonWebCache直接为表层的 UIKit框架提供接口, SDWebImageManger&#xff08;SDWebImageManager…

SDWebImage的主流程

SDWebImage提供了UIImageView的分类来实现从网络端下载数据并缓存到内存和磁盘。非常的流行,现在就主流程分析下. 主要的学习链接 &#xff1a;SDWebImage源码解读 - 简书 SDWebImage有如下特点&#xff1a; 提供了UIImageView和UIButton的分类。以支持加载网络图片并缓存…

SDWebImage的缓存策略

SDWebImage 相信对大多数开发者来说&#xff0c;都是一个不陌生的名字。它除了帮助我们读取网络图片&#xff0c;还会处理这些图片的缓存。它的缓存机制到底是什么样的呢&#xff0c;让我给跟大家唠叨唠叨&#xff0c;希望你能有收获。 基本结构 闲言少叙&#xff0c;咱们这就…

SDWebImage源码解析

这段时间研究了一下SDWebImage源码&#xff0c;因个人能力有限&#xff0c;如有不对的地方&#xff0c;请指出或留言&#xff0c;谢谢&#xff01; SDWebImage是一个开源的第三方库&#xff0c;它提供了UIImageView的一个分类&#xff0c;以支持从远程服务器下载并缓存图片的功…

【iOS】SDWebImage

文章目录 SDWebImage日常使用一些主要功能获取图片缓存 缓存机制独立的异步图像下载独立的异步图像缓存 图片加载全过程 源码分析架构图结构SDWebImageManager1. SDWebImageOptions2. SDWebImageManagerDelegate SDWebImageCompatSDWebImageCompat.hSDWebImageCompat.m sd_imag…

开源框架:SDWebImage

引言: SDWebImage是我搞iOS以来少数佩服的框架,膜拜一下作者.真的写的非常棒! 这套开源框架还是蛮重要的, 涉及到异步加载图片源和自动缓存. 我们如果能够熟练使用其API 就可以实现很多复杂的需求了. 作者依旧在更新,目前3.0 版本已经非常强大! 简化了更多的API接口.加强了…

iOS 第三方框架-SDWebImage解读

在iOS的图片加载框架中&#xff0c;SDWebImage可谓是占据大半壁江山。它支持从网络中下载且缓存图片&#xff0c;并设置图片到对应的UIImageView控件或者UIButton控件。在项目中使用SDWebImage来管理图片加载相关操作可以极大地提高开发效率&#xff0c;让我们更加专注于业务逻…

iOS——SDWebImage解读

前言 在iOS的图片加载框架中&#xff0c;SDWebImage占据了大半壁江山。它提供了UIImageView的一个分类&#xff0c;支持从网络中下载且缓存图片&#xff0c;并设置图片到对应的UIImageView控件或者UIButton控件。在项目中使用SDWebImage来管理图片加载相关操作可以极大地提高开…

SDWebImage异步加载图片及缓存的管理与清理

一、SDWebImage介绍 1、在项目的开发过程中&#xff0c;我们经常会用到异步加载图片的功能&#xff0c;先从网络上异步下载图片&#xff0c;然后通过UIImageView显示在屏幕上。这是一个经常使用的功能&#xff0c;基本上所有的联网应用程序都要用到的功能&#xff0c;现在GitH…

iOS SDWebImage详细介绍

在iOS的图片加载框架中&#xff0c;SDWebImage使用频率非常高。它支持从网络中下载且缓存图片&#xff0c;并设置图片到对应的UIImageView控件或者UIButton控件。在项目中使用SDWebImage来管理图片加载相关操作可以极大地提高开发效率&#xff0c;让我们更加专注于业务逻辑实现…

JNA入门

1&#xff0c;什么是JNA&#xff1f; JNA全称Java Native Access&#xff0c;是一个建立在JNI技术之上的Java开源框架。 2&#xff0c;JNA有什么用&#xff1f; Java开发过程中&#xff0c;有时候会需要和C&#xff0c;C等交互&#xff0c;JNA相当于中间的适配器 3&#xf…

JNA —— Java调用C/C++动态库

工作所需&#xff0c;要使用Java调用c/c的动态库&#xff0c;实现Java程序使用动态库中的函数。 搜索了一番&#xff0c;常用的有JNI、JNA方法。 JNI&#xff08;Java Native Interface&#xff09; JNI定义了一种公用的语法&#xff0c;当Java和c/c都遵循这样的语法时就可以互…

关于JAVA中的JNA

1、jna是什么 jna是java native access的简称&#xff0c;用他可以调用C、C代码&#xff0c;特别是windows中强大的库文件&#xff08;dll&#xff0c;在linux下是so文件&#xff09;&#xff0c;这样java就可以操控底层的一些东西&#xff0c;比如调用加密机、智能卡之类的 2、…

JNA与JNI谁更受青睐呢

JNA(Java Native Access)框架是一个开源的Java框架&#xff0c;是SUN公司主导开发的&#xff0c;建立在经典的JNI的基础之上的一个框架。非常强大、易用。其中JNA是对JNI的封装&#xff0c;能让java使用者更好的使用本地的动态库 一、JNA与JNI的比较 JNI: JNI允许Java代码和其…