当前位置:网站首页>语音数据采集-实时语音数据可视化
语音数据采集-实时语音数据可视化
2022-07-27 09:57:00 【用户9925864】
1、安装依赖
pip install pyaudio
pip install pylab2、语音数据展示
import pyaudio
import numpy as np
CHUNK = 4096 # 每次采集的数据点数
RATE = 44100 # 采样频率
p=pyaudio.PyAudio() # 启动类
stream=p.open(format=pyaudio.paInt16,channels=1,rate=RATE,input=True,
frames_per_buffer=CHUNK) #输入设备
# 创建一个numpy来保存每次采集的数据
for i in range(10): #
data = np.fromstring(stream.read(CHUNK),dtype=np.int16)
print(data)
# 关闭音频采集流
stream.stop_stream()
stream.close()
p.terminate()3、声音波形可视化
首先采集数据,然后保存为图片,新建一个网页,在网页上展示波形图
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)): #持续10s
soundplot(stream)
stream.stop_stream()
stream.close()
p.terminate()网页代码
<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>效果如图
边栏推荐
- 并发之线程状态转换
- Shell函数、系统函数、basename [string / pathname] [suffix] 可以理解为取路径里的文件名称 、dirname 文件绝对路径、自定义函数
- Concurrent thread state transition
- Overview of PCL modules (1.6)
- LeetCode.814. 二叉树剪枝____DFS
- Food safety | the more you eat junk food, the more you want to eat it? Please keep this common food calorimeter
- Leetcode.814. binary tree pruning____ DFS
- PCL的ICP配准示例
- 超赞的卡尔曼滤波详解文章
- 数据分析如何解决商业问题?这里有份超详细攻略
猜你喜欢

Excellent Kalman filter detailed article

Concurrent Park and unpark description

Open3d library installation, CONDA common instructions, importing open3d times this error solving environment: failed with initial frozen solve Retrying w

Ant高级-path和fileset

Uninstall cuda11.1

食品安全 | 菜板环境很重要,这些使用细节你知道吗?

RobotFramework+Eclispe环境安装篇

WGAN、WGAN-GP、BigGAN

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

About new_ Online_ Judge_ 1081_ Thoughts on Goldbach's conjecture
随机推荐
Come on, chengxujun
Leetcode.1260. 2D grid migration____ In situ violence / dimensionality reduction + direct positioning of circular array
省应急管理厅:广州可争取推广幼儿应急安全宣教经验
女粉想要找男朋友,竟是为了...
Introduction to regular expressions of shell, general matching, special characters: ^, $,., * Character range (brackets): [], special characters: \, matching mobile phone number
Exercises --- quick arrangement, merging, floating point number dichotomy
Looking for a job for 4 months, interviewing 15 companies and getting 3 offers
Ant advanced -path and fileset
活体检测综述
TFlite 的简单使用
NFS 服务器的搭建
Shell函数、系统函数、basename [string / pathname] [suffix] 可以理解为取路径里的文件名称 、dirname 文件绝对路径、自定义函数
pytorch中对BatchNorm2d()函数的理解
Learn typescript (1)
Shell运算符、$((运算式))” 或 “$[运算式]、expr方法、条件判断、test condition、[ condition ]、两个整数之间比较、按照文件权限进行判断、按照文件类型进行判断
NFT system development - Tutorial
StyleGAN论文笔记+修改代码尝试3D点云生成
Data visualization
Leetcode.565. array nesting____ Violent dfs- > pruning dfs- > in situ modification
3D修复论文:Shape Inpainting using 3D Generative Adversarial Network and Recurrent Convolutional Networks