资源简介
此文件用于语音在线传输,基于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 封装的爬取社保信息
相关资源
- 二级考试python试题12套(包括选择题和
- pywin32_python3.6_64位
- python+ selenium教程
- PycURL(Windows7/Win32)Python2.7安装包 P
- 英文原版-Scientific Computing with Python
- 7.图像风格迁移 基于深度学习 pyt
- 基于Python的学生管理系统
- A Byte of Python(简明Python教程)(第
- Python实例174946
- Python 人脸识别
- Python 人事管理系统
- 基于python-flask的个人博客系统
- 计算机视觉应用开发流程
- python 调用sftp断点续传文件
- python socket游戏
- 基于Python爬虫爬取天气预报信息
- python函数编程和讲解
- Python开发的个人博客
- 基于python的三层神经网络模型搭建
- Tarcotron2(文本转语音)
- python实现自动操作windows应用
- python人脸识别(opencv)
- python 绘图(方形、线条、圆形)
- python疫情卡UN管控
- python 连连看小游戏源码
- 基于PyQt5的视频播放器设计
- 一个简单的python爬虫
- csv文件行列转换python实现代码
- Python操作Mysql教程手册
- Python Machine Learning Case Studies
评论
共有 条评论