大间隔决定内容 小间隔决定速度和音色, 前面的音色 会和后面的混合影响

import matplotlib.pyplot as plt
import librosa
import numpy as np
from scipy.io import wavfile
from collections import Counter
def tian_chong(j,a,b,f):
# x = 0.9 * np.sin(np.linspace(a, b, j)) + 0.1 * np.sin(np.linspace(np.pi, f * np.pi,j))
x = 0.9 *np.sin(np.linspace(a, b, j))
return x

def fen_jie(radio):
x_index = np.where((radio[1:] / (radio[:-1] + 0.0000001)) < 0)
# 相邻穿过0点位置的间隔
x_index_list = np.array([j - i for i, j in zip([0] + x_index[0].tolist(), x_index[0].tolist() + [radio.size])])
# 翻倍
# x_index_list*=5

x_index_list_h = [max(np.abs(radio[i:j])) if radio[i:j].size!=0 else 0 for i, j in
zip([0] + x_index[0].tolist(), x_index[0].tolist() + [radio.size])]
return x_index_list,x_index_list_h
def huan_yuan(x_index_list,x_index_list_h):
# x_index_list[x_index_list<3]
# x_index_list*=np.array([1 if i%10==0 else 6 for i in range(x_index_list.size)])
# x_index_list[x_index_list<9]=9


res = np.hstack([x_index_list_h[i] * tian_chong(j,0, np.pi ,22) if i % 2 == 0 else
x_index_list_h[i] * tian_chong(j,np.pi,2 *np.pi, 22) for i, j in
enumerate(x_index_list)])
return res


radio,sample=librosa.load("2500中文常用字发音/晚1627285350.wav",16000)
# radio1,sample1=librosa.load("160_1_recorded2_041_fast.wav",16000)
radio=radio[500:3000]

x,h=fen_jie(radio)

# x=x**2 事实证明 间隔之间的比值 决定了内容
# x1,h1=fen_jie(radio1)

# 连续间距变化小于3的 np.abs(x[1:]-x[:-1])<3
res=huan_yuan(x,h)
# res=res[np.abs(res)>0.0005]
# res1=huan_yuan(x1,h1)
wavfile.write("160_1_recorded2_001_normal_copy.wav",16000,res)
# wavfile.write("160_1_recorded2_001_normal_copy1.wav",16000,res1)
x[x<9]=9
# 大间隔决定内容 小间隔决定速度和音色, 前面的音色 会和后面的混合影响
plt.plot([i for i in range(x.size)],x)
# plt.plot([i for i in range(x1.size)],x1)


# plt.plot([i for i in range(res.size)],res)
# plt.plot([i for i in range(res1.size)],res1)


plt.show()
if __name__ == '__main__':
pass

声音的密码_机器学习

声音的密码_几何学_02

谁能想象两个图的发音是一样的

经过本人发现,波的形状基本不会影响发音

实际影响发音的是0 附近 点的间隔 如下图所示 1到2的间隔

2到3的间隔 3到4的间隔 4到5的间隔决定声的内容 只要保持

每个中间有一个固定的数且都是正或者是负即可,原因应该是声音是纵波,和疏密有关

声音的密码_取值_03

import matplotlib.pyplot as plt
import librosa
import numpy as np
def tian_chong(j,a,b,f):
x = 0.9 * np.sin(np.linspace(a, b, j)) + 0.1 * np.sin(np.linspace(np.pi, f * np.pi,j))
return x

def fen_jie(radio):
x_index = np.where((radio[1:] / (radio[:-1] + 0.0000001)) < 0)
# 相邻穿过0点位置的间隔
x_index_list = np.array([j - i for i, j in zip([0] + x_index[0].tolist(), x_index[0].tolist() + [radio.size])])
# 翻倍
# x_index_list*=5

x_index_list_h = [max(np.abs(radio[i:j])) if radio[i:j].size!=0 else 0 for i, j in
zip([0] + x_index[0].tolist(), x_index[0].tolist() + [radio.size])]
return x_index_list,x_index_list_h
def huan_yuan(x_index_list,x_index_list_h):
res = np.hstack([x_index_list_h[i] * tian_chong(j,0.02 + np.pi, 2 * np.pi - 0.02,101) if i % 2 == 0 else
x_index_list_h[i] * tian_chong(j,0.02, np.pi - 0.02, 101) for i, j in
enumerate(x_index_list)])
return res


radio,sample=librosa.load("2500中文常用字发音/张1627285025.wav",16000)
radio1,sample1=librosa.load("2500中文常用字发音/章1627285373.wav",16000)


x,h=fen_jie(radio)
x1,h1=fen_jie(radio1)
# 连续间距变化小于3的 np.abs(x[1:]-x[:-1])<3
res=huan_yuan(x,h)
res1=huan_yuan(x1,h1)



plt.plot([i for i in range(res.size)],res)
plt.plot([i for i in range(res1.size)],res1)

plt.show()
if __name__ == '__main__':
pass
import matplotlib.pyplot as plt
import librosa
import numpy as np
def fen_jie(radio):
x_index = np.where((radio[1:] / (radio[:-1] + 0.0000001)) < 0)
# 相邻穿过0点位置的间隔
x_index_list = np.array([j - i for i, j in zip([0] + x_index[0].tolist(), x_index[0].tolist() + [radio.size])])
# 翻倍
# x_index_list*=5

x_index_list_h = [max(np.abs(radio[i:j])) if radio[i:j].size!=0 else 0 for i, j in
zip([0] + x_index[0].tolist(), x_index[0].tolist() + [radio.size])]
return x_index_list,x_index_list_h
def huan_yuan(x_index_list,x_index_list_h):
res = np.hstack([x_index_list_h[i] * np.sin(np.linspace(0.02 + np.pi, 2 * np.pi - 0.02, j)) if i % 2 == 0 else
x_index_list_h[i] * np.sin(np.linspace(0.02, np.pi - 0.02, j)) for i, j in
enumerate(x_index_list)])
return res


radio,sample=librosa.load("2500中文常用字发音/张1627285025.wav",16000)
radio1,sample1=librosa.load("2500中文常用字发音/章1627285373.wav",16000)


x,h=fen_jie(radio)
x1,h1=fen_jie(radio1)
# 连续间距变化小于3的 np.abs(x[1:]-x[:-1])<3
res=huan_yuan(x,h)
res1=huan_yuan(x1,h1)



plt.plot([i for i in range(res.size)],res)
plt.plot([i for i in range(res1.size)],res1)
plt.show()
if __name__ == '__main__':
pass
import matplotlib.pyplot as plt
import librosa
import numpy as np
radio,sample=librosa.load("2500中文常用字发音/与1627284797.wav",16000)
# 穿过0点的位置
x_index=np.where((radio[1:]/(radio[:-1]+0.0000001))<0)
# 相邻穿过0点位置的间隔
x_index_list=np.array([j-i for i ,j in zip([0]+x_index[0].tolist(),x_index[0].tolist()+[radio.size])])
x_index_list_h=[max(np.abs(radio[i:j])) for i ,j in zip([0]+x_index[0].tolist(),x_index[0].tolist()+[radio.size])]
# 间隔的种类,可以对间隔同时操作 只要相邻间隔的比值不变
x_index_set=set(x_index_list)
# 只要根据间隔交替产生sin(0-pi) sin(pi-2pi) 就可完成任务
# 这里需要把顶点取值去去掉就会好看些
# 使用
res=np.hstack([x_index_list_h[i]*np.sin(np.linspace(0.02+np.pi,2*np.pi-0.02,j)) if i%2==0 else x_index_list_h[i]*np.sin(np.linspace(0.02,np.pi-0.02,j)) for i ,j in enumerate(x_index_list) ])
# plt.plot([i for i in range(radio.size)],radio)
# 可以控制0-2pi 的范围进行外形调整,为了美观和辅助清晰度
# res=res*np.sin(np.linspace(0,2*np.pi ,res.size))
res=res[np.abs(res)<0.9]
#
plt.plot([i for i in range(res.size)],res)
plt.show()
if __name__ == '__main__':
pass

最新版本

import matplotlib.pyplot as plt
import librosa
import numpy as np
from scipy.io import wavfile
radio,sample=librosa.load("2500中文常用字发音/上1627284798.wav",16000)
# 穿过0点的位置
x_index=np.where((radio[1:]/(radio[:-1]+0.0000001))<0)
# 相邻穿过0点位置的间隔
x_index_list=x_index[0][1:]-x_index[0][:-1]
# 间隔的种类,可以对间隔同时操作 只要相邻间隔的比值不变
x_index_set=set(x_index_list)
# 只要根据间隔交替产生sin(0-pi) sin(pi-2pi) 就可完成任务
# 这里需要把顶点取值去去掉就会好看些
res=np.hstack([np.sin(np.linspace(0.02+np.pi,2*np.pi-0.05,j)) if i%2==0 else np.sin(np.linspace(0.05,np.pi-0.05,j)) for i ,j in enumerate(x_index_list) ])
# plt.plot([i for i in range(radio.size)],radio)
# 可以控制0-2pi 的范围进行外形调整,为了美观和辅助清晰度
# res=res*np.sin(np.linspace(0,12*np.pi ,res.size))
res=res*np.sin(np.linspace(0,4*np.pi ,res.size))
# res=res[np.abs(res)<0.9]
wavfile.write("shang.wav",16000,res)
#
plt.plot([i for i in range(res.size)],res)
plt.show()
if __name__ == '__main__':
pass

以前的版本

import matplotlib.pyplot as plt
import librosa
import numpy as np
radio,sample=librosa.load("2500中文常用字发音/上1627284798.wav",16000)
# 穿过0点的位置
x_index=np.where((radio[1:]/(radio[:-1]+0.0000001))<0)
# 相邻穿过0点位置的间隔
x_index_list=x_index[0][1:]-x_index[0][:-1]
# 间隔的种类,可以对间隔同时操作 只要相邻间隔的比值不变
x_index_set=set(x_index_list)
# 只要根据间隔交替产生sin(0-pi) sin(pi-2pi) 就可完成任务
# 这里需要把顶点取值去去掉就会好看些
res=np.hstack([np.sin(np.linspace(0.02+np.pi,2*np.pi-0.05,j)) if i%2==0 else np.sin(np.linspace(0.05,np.pi-0.05,j)) for i ,j in enumerate(x_index_list) ])
# plt.plot([i for i in range(radio.size)],radio)
# 可以控制0-2pi 的范围进行外形调整,为了美观和辅助清晰度
# res=res*np.sin(np.linspace(0,2*np.pi ,res.size))
#
plt.plot([i for i in range(res.size)],res)
plt.show()
if __name__ == '__main__':
pass
import matplotlib.pyplot as plt
import librosa
import numpy as np
radio,sample=librosa.load("2500中文常用字发音/上1627284798.wav",16000)
# 穿过0点的位置
x_index=np.where((radio[1:]/radio[:-1])<=0)
# 相邻穿过0点位置的间隔
x_index_list=x_index[0][1:]-x_index[0][:-1]
# 间隔的种类,可以对间隔同时操作 只要相邻间隔的比值不变
x_index_set=set(x_index_list)
# 只要根据间隔交替产生sin(0-pi) sin(pi-2pi) 就可完成任务
# 这里需要把顶点取值去去掉就会好看些
res=np.hstack([np.sin(np.linspace(0.02+np.pi,2*np.pi-0.05,j)) if i%2==0 else np.sin(np.linspace(0.05,np.pi-0.05,j)) for i ,j in enumerate(x_index_list) ])
# plt.plot([i for i in range(radio.size)],radio)
# 可以控制0-2pi 的范围进行外形调整,为了美观和辅助清晰度
# res=res*np.sin(np.linspace(0,2*np.pi ,res.size))

plt.plot([i for i in range(res.size)],res)
plt.show()
if __name__ == '__main__':
pass
import matplotlib.pyplot as plt
import numpy as np


def ax_b(a, x, b):
a = np.repeat(a.reshape(1, -1), x1.shape[0], 0)
b = np.repeat(b.reshape(1, -1), x1.shape[0], 0)
return a * x + b


#
s = np.array([0, 680, 1680, 4560])
e = np.array([1150, 1980, 5000, 5500])
h_index = np.array([520, 1350, 3250, 5000])
l1 = h_index - s
l2 = e - h_index
b = np.array([0.05, 0.3, 0.45, 0.15])

# 随机设置 三角底边 l1+l2 长度100个
# l1 = np.random.randint(10, 20, 100)
# l2 = np.random.randint(20, 30, 100)
# # 设计三角高度
# b = np.random.randint(60, 90, 100)
# 计算ax+b 的a
a1 = b / l1
a2 = -b / l2
# 在三角内取值
x1 = np.linspace(-l1, 0, 2000)
x2 = np.linspace(0, l2, 2000)
# 带入y=ax+b的y
y1 = ax_b(a1, x1, b)
y2 = ax_b(a2, x2, b)
# 设置12个f 加和
res1 = [(y1 * np.sin(i ** 2 * np.pi * x1)).tolist() for i in range(1, 13)]
res2 = [(y2 * np.sin(i ** 2 * np.pi * x2)).tolist() for i in range(1, 13)]

res1 = np.sum(np.array(res1), 0)
res2 = np.sum(np.array(res2), 0)

# 调整l1 和l2 b 就可以调整菱形的形状
# 将100个res1和res2 组合起来
res = [np.hstack([res1[:, j], res2[:, j]]) for j in range(4)]
sample_step=(4000/(e-s)).astype("int")
# 单独显示
# for j in res:
# plt.plot([i for i in range(j.size)],j)
# # plt.plot([i for i in range(j.size)],np.abs(np.fft.fft(j)))
# plt.show()
# 4一起显示
# 拼接的时候要有重叠
rest = []
for re_data, step in zip(res, sample_step):
print()
new_data=re_data[::step]
rest.append(new_data)
# 交叉叠加占比计算目前是多少
j_d_l=(((e[:-1]-s[1:]) /(e-s)[:-1]) * np.array([i.size for i in rest])[:-1]).astype("int")
# 计算 后面开始点
s_list=[]
# e_list=[]
s_=0
d_list=[i.size for i in rest]
for i,d in enumerate(d_list[:-1]):
s_+=d
s_=s_ - j_d_l[i]
# e_list.append(d)
s_list.append(s_)
res_=np.zeros(s_list[-1] + d_list[-1])
s_list=[0]+s_list
for i,s_data in enumerate(s_list) :
new_data = np.zeros(s_list[-1] + d_list[-1])
new_data[s_data:s_data+rest[i].size]=rest[i]
res_+=new_data
# print()


# 进行降采样
plt.plot([i for i in range(res_.size)], res_)
# plt.plot([i for i in range(res.size)],np.abs(np.fft.fft(res)))
plt.show()
if __name__ == '__main__':
pass