Open source speech format speex tutorial (for iOS)

Source: Internet
Author: User
Tags tmp folder

During the past two days, I tried to implement something similar to the functions of the walkie talkie. I made two demos, one of which was implemented using the Lib-Amr library in the AMR format. There were off-the-shelf tutorials on the Internet, so it is better to implement it. The other is the speex library. There are a lot of people mentioned here, but there are not many tutorials. I hate the totem tutorial. Many unknown things make us confused, after three days on the Internet, you can finally create a decent demo. In the demo, I recorded a. CAF format PCM audio.
Encode it into the speex format and convert it back to the PCM format. Of course, the demo only implements audio encoding and decoding, and does not add many functions.
I tested the 60-second recording (8 kHz, single-channel). The AMR size in the minimum format is kb and the size of the one-minute recording file is similar. The speex format is 18 K at the minimum but fuzzy, the acceptable size is 30 kb, so it is still smaller than the AMR format. In addition, the speex library can process sound such as noise reduction, gain, and mute determination. However, considering that android supports audio in the AMR format and WP, we finally chose to convert the audio to the AMR format. Unfortunately, Apple does not support AMR now, so transcoding is required, next, let's take a step-by-step demo with you.


Compile the static Library:
This really makes me puzzled for a day. In fact, it should be very easy for C/C ++ programmers in Linux to do this, but all of them are returned to the teacher, according to the tutorial on the Internet, it has been a long time.
First download the source file you need. Because speex depends on the Ogg library, download the Ogg Library first. Here I package and upload it together. You can also download it from the official website.
Source file:
Libogg-1.3.0.zip (496 K) Downloads: 600 speex-1.2rc1.tar
(3890 K) Downloads: 558
Because the compilation is carried out in command line mode, open the terminal, first enter the folder where Ogg is located, we first compile Ogg
In addition, I use xcode4.4.1. You need to adjust it slightly based on your own xcode commands. The 4.2 compilation tutorials are available online and I will not repeat them here.
Enter the following content on the terminal:
1.ogg-i386 Library
. /Configure-Prefix =/users/your computer username/desktop/speexlibrary/libogg-1.3.0/i386-host = i386-apple-darwin-build = x86_64-apple-darwin11.3.0 cc = "/applications/xcode. APP/contents/developer/usr/llvm-gcc-4.2/bin/llvm-gcc-4.2
-STD = c99-arch i386-isysroot/applications/xcode. APP/contents/developer/platforms/iphonesimulator. Platform/developer/sdks/iphonesimulator5.1.sdk /"


Make
Make install
Make clean (Be sure to be clean, otherwise the first compiled content will be compiled later)
2. Library of ogg-armv6
. /Configure-Prefix =/users/your computer username/desktop/speexlibrary/libogg-1.3.0/armv6-host = armv6-apple-darwin-build = x86_64-apple-darwin11.3.0 cc = "/applications/xcode. APP/contents/developer/platforms/iphoneos. platform/developer/usr/llvm-gcc-4.2/bin/llvm-gcc-4.2
-STD = c99-arch armv6-isysroot/applications/xcode. APP/contents/developer/platforms/iphoneos. Platform/developer/sdks/iphoneos5.1.sdk /"


Make
Make install
Make clean


3. Library of ogg-armv7
./Configure-Prefix =/users/your computer username/desktop/speexlibrary/libogg-1.3.0/armv7-host = armv7-apple-darwin
-Build = x86_64-apple-darwin11.3.0 cc = "/applications/xcode. APP/contents/developer/platforms/iphoneos. platform/developer/usr/llvm-gcc-4.2/bin/llvm-gcc-4.2-STD = c99-arch armv7-isysroot/applications/xcode. APP/contents/developer/platforms/iphoneos. platform/developer/sdks/iphoneos5.1.sdk /"


Make
Make install
Make clean


Then compile the speex Library:
1. Library of speex-i386
./Configure-Prefix =/users/your computer username/desktop/speexlibrary/speex-1.2rc1/i386-host = i386-apple-darwin
-Disable-shared-enable-static-Disable-oggtest-Disable-fixed-point-enable-float-API-build = x86_64-apple-darwin11.3.0-with-Ogg =/users/your computer user name /desktop/speexlibrary/libogg-1.3.0/i386
Cc = "/applications/xcode. APP/contents/developer/usr/llvm-gcc-4.2/bin/llvm-gcc-4.2-STD = c99-arch i386-isysroot/applications/xcode. APP/contents/developer/platforms/iphonesimulator. platform/developer/sdks/iphonesimulator5.1.sdk /"


Make
Make install
Make clean


2. Library of speex-armv6
./Configure-Prefix =/users/your computer username/desktop/speexlibrary/speex-1.2rc1/armv6-host = armv6-apple-darwin
-Disable-shared-enable-static-Disable-oggtest-enable-fixed-point-Disable-float-API-build = x86_64-apple-darwin11.3.0-with-Ogg =/users/your computer user name /desktop/speexlibrary/libogg-1.3.0/armv6
Cc = "/applications/xcode. APP/contents/developer/platforms/iphoneos. platform/developer/usr/llvm-gcc-4.2/bin/llvm-gcc-4.2-STD = c99-arch armv6-isysroot/applications/xcode. APP/contents/developer/platforms/iphoneos. platform/developer/sdks/iphoneos5.1.sdk /"


Make
Make install
Make clean


3. Library of speex-armv7
./Configure-Prefix =/users/your computer username/desktop/speexlibrary/speex-1.2rc1/armv7-host = armv7-apple-darwin
-Disable-shared-enable-static-Disable-oggtest-enable-fixed-point-Disable-float-API-build = x86_64-apple-darwin11.3.0-with-Ogg =/users/your computer user name /desktop/speexlibrary/libogg-1.3.0/armv7
Cc = "/applications/xcode. APP/contents/developer/platforms/iphoneos. platform/developer/usr/llvm-gcc-4.2/bin/llvm-gcc-4.2-STD = c99-arch armv7-isysroot/applications/xcode. APP/contents/developer/platforms/iphoneos. platform/developer/sdks/iphoneos5.1.sdk /"


Make
Make install
Make clean


Finally, merge the static library, enter the speexlibrary folder, and enter the terminal:
Lipo-create i386/lib/libogg. A armv6/lib/libogg. A armv7/lib/libogg. A-output libogg.
Lipo-create i386/lib/libspeex. A armv6/lib/libspeex. A armv7/lib/libspeex. A-output libspeex.
Lipo-create i386/lib/libspeexdsp. A armv6/lib/libspeexdsp. A armv7/lib/libspeexdsp. A-output libspeexdsp.


Now, the compilation is complete. If the static library fails to be merged, check the above steps (I forgot to make clean at the time, and the i386. A file is compiled). You can use lipo
-In the info XXX. A file, the platform information used by the files in the library will be displayed later. Normally, i386, armv6, and armv7 will be displayed successfully. Of course, I have also uploaded the packaged library for your convenience.
The packaged speex Library:
_Speex.zip (821 K) Downloads: 524



Start our project below:
Create a new project and import our static library. I dragged the package directly to the project. Remember to set the path for searching the static library. At that time, I forgot to set the path, the result is that the header files cannot be found. After the import, the topic is displayed.


How can I record a 60-Second. CAF file for convenience? One thousand words are omitted here...
I will not explain the detailed demo explanation. Let's take a look at the demo. Here I will explain the steps.
1. We need to remove the file header from the. CAF file to obtain pure PCM data.
2. encode pure PCM data into pure speex format
3. Add a file header for data in pure speex format
4. Export the speex file (I didn't do this step, because it is transcoding in the program, so it is not required. I use nsdata directly. I don't know the extension name of the speex file. Is it Ogg ?, Supplemented by knowledge)
--------------- Split -------------
4. Decode speex format data (with file headers) to pure PCM format
5. Add a WAV format file header
6. Write WAV data into the file and export the caf file (the exported file can be found in the TMP folder of the simulated project. A caf file can be played by clicking it ).


The following is my demo. Please compare it with the official speex User Manual. The user manual contains the C language sample code for encoding and decoding, which must be carefully studied.
My demo
Test_speex_001.zip (1585 K) Downloads: 1211
Hope to help you

---------------------------------------------------------------------------------------------------------------------------- 2.12.30 success ----------------------------------------------------------------------------------------------------------
I wanted to write down the speex demo in depth, but I have studied it for more than a week. I know it may be worse than everyone else. I can't take the time to study the system. Many questions cannot be answered due to limited strength. Sorry. In addition, I found a good book about core audio on the Internet. Of course, it is in English and I will share it with you.
Learn core audio.pdf.zip (8034 K) Downloads: 136

Summary ----------------------------------------------------------------------------------------------------------

1. Problems with debugging on a real machine

Undefined symbols for architecture armv7:
"_ Speex_decode", referenced from:
_ Decodespeextowave in speexcodec. o
(Maybe you meant: _ speex_decode_stereo_int, _ speex_decode_native, _ speex_decoder_init, _ speex_decode_int, _ speex_decoder_destroy, _ speex_decoder_ctl)
"_ Speex_encode", referenced from:
_ Encodepcmtorawspeex in speexcodec. o
(Maybe you meant: _ speex_encode_stereo_int, _ speex_encoder_init, _ speex_encoder_ctl, _ speex_encoder_destroy, _ speex_encode_native, _ speex_encode_int)
Ld: symbol (s) not found for architecture armv7
Clang: Error: Linker command failed with exit code 1 (use-V to see Invocation)

"Because the speex_encode and speex_decode methods cannot be found during compilation, I used the speex_encode_int and speex_decode_int methods to replace them, so that the parameters are also changed to the spx_int16_t type"
This method is provided according to another post on this site., Laniu post


2. Four warnings about the project. Someone has tried to note it because of repeated definitions and can compile it. Thank you!

3. About int TMP = 1; // BPS?
Void * encode_state =
Speex_encoder_init (& speex_nb_mode );
Speex_encoder_ctl (encode_state,
Speex_set_quality, & TMP );
When TMP = 8, the sound quality is restored, but the compressed file is also large.
Personal statistics, 60 seconds of recording
TMP value:
0 --> 18 K
1 --> 30 K
2 --> 45 K
3 --> 60 k
4 --> 60 k
5 --> 84 K
6 --> 84 K
7 --> 114 K
8 -- & gt; 114 K
9 --> 138 K
10 --> 186 K

In fact, the corresponding parameter value corresponds to a certain bit rate. Please refer to the Manual for details.

From: http://www.cocoachina.com/bbs/read.php? Tid = 114755

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.