当前位置:网站首页>Voice data acquisition - real time voice data visualization
Voice data acquisition - real time voice data visualization
2022-07-27 10:22:00 【User 9925864】
1、 Installation dependency
pip install pyaudio
pip install pylab2、 Voice data display
import pyaudio
import numpy as np
CHUNK = 4096 # The number of data points collected each time
RATE = 44100 # sampling frequency
p=pyaudio.PyAudio() # Start class
stream=p.open(format=pyaudio.paInt16,channels=1,rate=RATE,input=True,
frames_per_buffer=CHUNK) # input device
# Create a numpy To save the data collected each time
for i in range(10): #
data = np.fromstring(stream.read(CHUNK),dtype=np.int16)
print(data)
# Close the audio capture stream
stream.stop_stream()
stream.close()
p.terminate()3、 Sound waveform visualization
First collect data , Then save as a picture , Create a new page , Display the wave chart on the web
import pyaudio
import numpy as np
import pylab
import time
RATE = 44100
CHUNK = int(RATE/20)
def soundplot(stream):
t1=time.time()
data = np.fromstring(stream.read(CHUNK),dtype=np.int16)
pylab.plot(data)
pylab.title(i)
pylab.grid()
pylab.axis([0,len(data),-2**16/2,2**16/2])
pylab.savefig("03.png",dpi=50)
pylab.close('all')
print("took %.02f ms"%((time.time()-t1)*1000))
if __name__=="__main__":
p=pyaudio.PyAudio()
stream=p.open(format=pyaudio.paInt16,channels=1,rate=RATE,input=True,
frames_per_buffer=CHUNK)
for i in range(int(20*RATE/CHUNK)): # continued 10s
soundplot(stream)
stream.stop_stream()
stream.close()
p.terminate()Web page code
<html>
<script language="javascript">
function RefreshImage(){
document.pic0.src="03.png?a=" + String(Math.random()*99999999);
setTimeout('RefreshImage()',50);
}
</script>
<body onload="RefreshImage()">
<img name="pic0" src="03.png">
</body>
</html>The effect is as shown in the picture
边栏推荐
猜你喜欢

Xiandai 003

vs2019社区版下载教程(详细)

Snowflake vs. databricks who is better? The latest war report in 2022

Mysql database experiment training 5, data query YGGL database query (detailed)

Shell process control (emphasis), if judgment, case statement, let usage, for ((initial value; loop control condition; variable change)) and for variable in value 1 value 2 value 3..., while loop

关于ETL的两种架构(ETL架构和ELT架构)

Practice and exploration of overseas site Seata of ant group

怎样关闭电脑开机自启动的应用

女粉想要找男朋友,竟是为了...

pytorch中对BatchNorm2d()函数的理解
随机推荐
备战金九银十Android面试准备(含面试全流程,面试准备工作面试题和资料等)
Girl fan wants to find a boyfriend, but it's for
FSM onehot answer record
Des/3des/aes differences
Ubuntu and MySQL quick start tutorial
[brother hero June training] day 23: dictionary tree
Metasploit-永恒之蓝攻击
Pygame: alien invasion
Preparation for Android interview (including the whole process of interview, interview preparation, interview questions and materials, etc.)
NFT system development - Tutorial
Stylegan paper notes + modify code to try 3D point cloud generation
Local connection to remote server database under Windows platform (I)
Shell read read console input, use of read
Color segmentation using kmeans clustering
Oracle调整数据文件大小杂谈
Matlab sound classification based on short-time neural network
Is Damon partgroupdef a custom object?
数学推理题:张王李赵陈五对夫妇聚会,见面握手
Pytorch installation (very detailed)
hdu5288(OO’s Sequence)