一 opuslib
这个是纯粹的opus封装,要比ogg的那个更底层,ogg的那个封装的太严了。很多业务不方便开展。
二 实例解析:
import opuslib import opuslib.api.encoder import opuslib.api.decoder import pyaudio import wave import struct import numpy as np import time #导入库 filename = "test2.wav" wave_read = wave.open(filename, "rb") wav_channels = wave_read.getnchannels() wav_samplewidth = wave_read.getsampwidth() wav_samplerate = wave_read.getframerate() wav_frames = wave_read.getnframes() output_filename = "output-"+filename wave_write = wave.open(output_filename, "wb") print("Writing wav into file '{:s}'".format(output_filename)) wave_write.setnchannels(1) wave_write.setframerate(16000) wave_write.setsampwidth(2) enc = opuslib.Encoder(fs = wav_samplerate,channels = 1 ,application = "audio")#创建编码器 enc._set_bandwidth(1105) enc._set_lsb_depth(16) enc._set_complexity(10) enc._set_bitrate(wav_samplerate*2) enc._set_vbr(1) enc._set_force_channels(1) enc._set_packet_loss_perc(0) dec = opuslib.Decoder(fs = wav_samplerate,channels = 1 )#创建解码器 wav_frame_cnt = 0 # Calculate the desired frame size (in samples per channel) desired_frame_duration = 20/1000 # milliseconds desired_frame_size = int(desired_frame_duration * 16000) while True: pcm = wave_read.readframes(desired_frame_size) if len(pcm) == 0: break encoutput = enc.encode(pcm,320)#开始编码,数据保存在encoutput中 decoutput = dec.decode(encoutput,320)#开始解码,数据保存在decoutput中 wave_write.writeframes(decoutput) print("end.")
三 数据分析
A 这个参数很详细,可以个性化配置。
B 最新的兼容性比较好了,安装比较方便。
作者:虚生 出处:https://www.cnblogs.com/dylancao/ 以音频和传感器算法为核心的智能可穿戴产品解决方案提供商 ,提供可穿戴智能软硬件解决方案的设计,开发和咨询服务。 勾搭热线:邮箱:1173496664@qq.com weixin:18019245820 市场技术对接群:347609188 |