苹果录音的格式为wav, 该格式文件体积较大(10秒100k左右), 为了缩小体积同时兼顾安卓, 可以将其转换成amr格式(能将100k缩小至10k左右, 安卓能播放amr格式, 苹果于ios4.3以后便不支持amr)
本文通过opencore-arm(下载最新库文件)将wav转换为amr
opencore-amr下载后
1.首先新建一个文件夹,将下载到的opencore-amr-0.1.5.tar.gz压缩包放到里面,然后进入这个文件夹,在里面创建build.sh文件(xcode中创建也可以),将以下脚本粘贴到文件里面
复制这段脚本时注意每行代码的后面不要有空格, 该段代码摘自大神大招致胜的博客, 由于第二个configure中没有 --host=arm-apple-darwin \ 导致编译不成功(本文已加)
#!/bin/sh
set -xe
VERSION="0.1.5"
SDKVERSION="10.3"
LIBSRCNAME="opencore-amr"
CURRENTPATH=`pwd`
mkdir -p "${CURRENTPATH}/src"
tar zxvf ${LIBSRCNAME}-${VERSION}.tar.gz -C "${CURRENTPATH}/src"
cd "${CURRENTPATH}/src/${LIBSRCNAME}-${VERSION}"
DEVELOPER=`xcode-select -print-path`
DEST="${CURRENTPATH}/lib-ios"
mkdir -p "${DEST}"
ARCHS="armv7 armv7s arm64 i386 x86_64"
# ARCHS="armv7"
LIBS="libopencore-amrnb.a libopencore-amrwb.a"
DEVELOPER=`xcode-select -print-path`
for arch in $ARCHS; do
case $arch in
arm*)
IOSV="-miphoneos-version-min=7.0"
if [ $arch == "arm64" ]
then
IOSV="-miphoneos-version-min=7.0"
fi
echo "Building for iOS $arch ****************"
SDKROOT="$(xcrun --sdk iphoneos --show-sdk-path)"
CC="$(xcrun --sdk iphoneos -f clang)"
CXX="$(xcrun --sdk iphoneos -f clang++)"
CPP="$(xcrun -sdk iphonesimulator -f clang++)"
CFLAGS="-isysroot $SDKROOT -arch $arch $IOSV -isystem $SDKROOT/usr/include -fembed-bitcode"
CXXFLAGS=$CFLAGS
CPPFLAGS=$CFLAGS
export CC CXX CFLAGS CXXFLAGS CPPFLAGS
./configure \
--host=arm-apple-darwin \
--prefix=$DEST \
--disable-shared --enable-static
;;
*)
IOSV="-mios-simulator-version-min=7.0"
echo "Building for iOS $arch*****************"
SDKROOT=`xcodebuild -version -sdk iphonesimulator Path`
CC="$(xcrun -sdk iphoneos -f clang)"
CXX="$(xcrun -sdk iphonesimulator -f clang++)"
CPP="$(xcrun -sdk iphonesimulator -f clang++)"
CFLAGS="-isysroot $SDKROOT -arch $arch $IOSV -isystem $SDKROOT/usr/include -fembed-bitcode"
CXXFLAGS=$CFLAGS
CPPFLAGS=$CFLAGS
export CC CXX CFLAGS CXXFLAGS CPPFLAGS
./configure \
--host=arm-apple-darwin \
--prefix=$DEST \
--disable-shared
;;
esac
make > /dev/null
make install
make clean
for i in $LIBS; do
mv $DEST/lib/$i $DEST/lib/$i.$arch
done
done
for i in $LIBS; do
input=""
for arch in $ARCHS; do
input="$input $DEST/lib/$i.$arch"
done
lipo -create -output $DEST/lib/$i $input
done
2.修改build.sh的权限,打开终端,cd到新建的文件夹,使用命令 chmod 777 build.sh 修改权限.
3.修改完成之后在终端执行 ./build.sh 完成后如图
头文件
.a库(使用libopencore-amrnb.a, libopencore-amrwb.a)
demo(包括.sh文件, 已编译好的库, 转换代码)
参考博客:
简书博客地址