更新时间:2022-08-18 GMT+08:00
音频输入模块示例-输入
音频输入模块示例如下所示:
#! /usr/bin/python3.7 import hilens import wave def run(): # 构造本地音频文件采集器并将解码后数据保存到wav文件 cap = hilens.AudioCapture("\tmp\test.aac") # 构造本地麦克风采集器 cap2 = hilens.AudioCapture(sample_rate=hilens.AUDIO_SAMPLE_RATE_16000, bit_width=hilens.AUDIO_BIT_WIDTH_16, nSamples=1000, sound_mode=hilens.AUDIO_SOUND_MODE_MONO) wav = wave.open("test.wav", "wb") wav.setnchannels(2) # 设置通道数为2 wav.setsampwidth(2) # 设置采样率为16Bit wav.setframerate(44100) #设置采样率 for i in range(100): # 读取500帧数据并写到文件(约12S) data = cap.read(5) wav.writeframes(data.tobytes()) wav.close() # 当前目录生成test.wav音频文件,可用常见播放器打开 if __name__ == '__main__': hilens.init("hello") run() hilens.terminate()
父主题: 音频输入模块