当前位置:网站首页>Pyaudio audio recording
Pyaudio audio recording
2022-06-24 21:03:00 【CrazyManhhh】
pyaudio Module calls microphone for audio recording
// An highlighted block
import wave
from pyaudio import PyAudio,paInt16
framerate=16000
NUM_SAMPLES=2000
channels=1
sampwidth=2
TIME=3
def save_wave_file(data):
'''save the date to the wavfile'''
filename = "./static/yuyin/record.wav"
wf=wave.open(filename,'wb')
wf.setnchannels(channels)
wf.setsampwidth(sampwidth)
wf.setframerate(framerate)
wf.writeframes(b"".join(data))
wf.close()
def my_record():
pa=PyAudio()
stream=pa.open(format = paInt16,channels=1,
rate=framerate,input=True,
frames_per_buffer=NUM_SAMPLES)
my_buf=[]
count=0
while count<TIME*10:# Control recording time
string_audio_data = stream.read(NUM_SAMPLES)
my_buf.append(string_audio_data)
count+=1
save_wave_file(my_buf)
stream.close()
pip install pyaudio Installation Library
边栏推荐
- Where is 5g really powerful? What is the difference with 4G?
- Openvino2022 dev tools installation and use
- Internet of things? Come and see Arduino on the cloud
- 海泰前沿技术|隐私计算技术在医疗数据保护中的应用
- Analysis of errors in JSON conversion using objectmapper
- maptalks:数据归一化处理与分层设色图层加载
- CVPR 2022 remembers Sun Jian! Tongji and Ali won the best student thesis award, and hekaiming was shortlisted
- C language to realize mine sweeping (simple version)
- Leetcode(455)——分发饼干
- JMeter parameterization
猜你喜欢

Set up your own website (14)

After screwing the screws in the factory for two years, I earned more than 10000 yuan a month by "testing" and counterattacked

物联网?快来看 Arduino 上云啦

顺序表的基本操作

Stackoverflow annual report 2022: what are developers' favorite databases?

传统的IO存在什么问题?为什么引入零拷贝的?

在Dialog中使用透明的【X】叉叉按钮图片

The JS method parameter passed a number beginning with 0. A magical problem occurred and bothered me for a long time

Procedural life: a few things you should know when entering the workplace

Mapstacks: data normalization and layered color layer loading
随机推荐
The JS method parameter passed a number beginning with 0. A magical problem occurred and bothered me for a long time
Basic operation of sequence table
顺序栈1.0版本
Rename and delete files
顺序表的基本操作
Background operation retry gave up; KeeperErrorCode = ConnectionLoss
C language to realize mine sweeping (simple version)
Leetcode(135)——分发糖果
Combination mode -- stock speculation has been cut into leeks? Come and try this investment strategy!
云计算发展的 4 个阶段,终于有人讲明白了
Memo mode - game archiving
红象云腾完成与龙蜥操作系统兼容适配,产品运行稳定
开放可编程基础设施(OPI)项目,重新定义DPU/IPU
Can the OPDS SQL component pass process parameters to the next component through context
Open programmable infrastructure (OPI) project, redefining dpu/ipu
Talking about the range of data that MySQL update will lock
"Super point" in "Meng Hua Lu", is the goose wronged?
首个大众可用PyTorch版AlphaFold2复现,哥大开源OpenFold,star量破千
Sleep revolution - find the right length of rest
Berkeley, MIT, Cambridge, deepmind and other industry leaders' online lectures: towards safe, reliable and controllable AI