资源简介
此文件用于语音在线传输,基于Python2.7,利用socket编程
代码片段和文件信息
import wave
import numpy as np
import matplotlib.pyplot as plt
from python_speech_features import mfcc
from math import cos sin sqrt pi
def read_file(file_name):
with wave.open(file_name ‘r‘) as file:
params = file.getparams()
_ _ framerate nframes = params[:4]
str_data = file.readframes(nframes)
wave_data = np.fromstring(str_data dtype=np.short)
time = np.arange(0 nframes) * (1.0 / framerate)
return wave_data time
return index1 index2
def find_point(data):
count1 count2 = 0 0
for index val in enumerate(data):
if count1 < 40:
count1 = count1 + 1 if abs(val) > 0.15 else 0
index1 = index
if count1 == 40 and count2 < 5:
count2 = count2 + 1 if abs(val) < 0.001 else 0
index2 = index
if count2 == 5:
break
return index1 index2
def select_valid(data):
start end = find_point(normalized(data))
print(start end)
return data[start:end]
def normalized(a):
maximum = max(a)
minimum = min(a)
return a / maximum
def compute_mfcc_coff(file_prefix=‘‘):
mfcc_feats = []
s = range(10)
I = [0 3 4 8]
II = [5 7 9]
Input = {‘‘: s ‘I‘: I ‘II‘: II ‘B‘: s}
for index file_name in enumerate(file_prefix + ‘{0}.wav‘.format(i) for i in Input[file_prefix]):
data time = read_file(file_name)
#data = select_valid(data)
#if file_prefix==‘II‘:data = select_valid(data)
mfcc_feat = mfcc(data 48000)[:75]
mfcc_feats.append(mfcc_feat)
t = np.array(mfcc_feats)
return np.array(mfcc_feats)
def create_dist():
for i m_i in enumerate(mfcc_coff_input): # get the mfcc of input
for j m_j in enumerate(mfcc_coff): # get the mfcc of dataset
# build the distortion matrix bwtween i wav and j wav
N = len(mfcc_coff[0])
distortion_mat = np.array([[0] * len(m_i)
for i in range(N)] dtype=np.double)
for k1 mfcc1 in enumerate(m_i):
for k2 mfcc2 in enumerate(m_j):
distortion_mat[k1][k2] = sqrt(
sum((mfcc1[1:] - mfcc2[1:])**2))
yield i j distortion_mat
- 上一篇:python实现谱聚类代码并进行可视化
- 下一篇:scrapy 封装的爬取社保信息
相关资源
- scrapy 封装的爬取社保信息
- python实现谱聚类代码并进行可视化
- 解析pcap数据包
- Python实现香农码_费诺码_霍夫曼码
- python svm 源码
- 基于python的推荐系统库
- 本地两个文件夹同步,python语言,l
- 图像相似度计算python
- 交大python课大作业
- 基于selenium模拟天眼查登录并爬取企业
- python小游戏完美解决大作业.zip
- Python编程 第四版 真正的完整版
- python开发用到的工具书籍一套全
- Python包:baidumapAPI
- python实现图书借阅系统
- python爬虫样例
- 特征空间可视化.py
- 希尔密码.py Python 矩阵实现希尔密码
- python 获取文件夹下文件名称并写入到
- python面向对象课件
- Python快速编程入门的课后习题答案(
- Python爬虫代码
- 搜集和整理的100道Python考试题.docx
- 手写体数字识别原始数据和贝叶斯代
- Python环境下利用matplotlib绘制发动机万
- 基于Python+Theano实现的Lenet5源代码(附
- Python 中文手册.chm
- python实现类似QQ群聊
- 淘宝秒杀python脚本
-
python 从xm
l文件中提取有用信息转
评论
共有 条评论