如何解决如何使用 Python 3
我必须制作一个 Python 算法,将 .wav 文件(带有莫尔斯电码消息)转换为可读文本。我做了一些操作来规范化文件中的数据:
import wave
import numpy as np
import matplotlib.pyplot as plt
import sys
import scipy.signal.signaltools as sigtool
from scipy.signal import find_peaks
def normalization(sig):
env = (sigtool.hilbert(sig))
threshold = 200
square_sig = (env > threshold)
return square_sig
wav = wave.open("Python.wav",'r')
# I got this file from website:
# https://www.meridianoutpost.com/resources/etools/calculators/calculator-morse-code.PHP?
# just typed 'python' and generated a .wav file
if wav.getnchannels()==2:
print("Stereo files are not supported!")
sys.exit(0)
# to make it easier I am operating only on monofiles
raw = wav.readframes(-1)
raw = list(np.frombuffer(raw,"Int16"))
# made a list with the values of signal
thresh = normalization(raw)
# thresholded values
binom,_ = find_peaks(thresh,height=0)
# and at the end I have converted these values into set of ones
plt.figure('raw')
plt.plot(raw)
plt.figure('threshold')
plt.plot(treshold)
plt.figure('binom')
plt.plot(binom,thresh[binom],'.')
plt.show()
在那之后,我必须计算一个和间隙的长度。根据摩尔斯电码的知识,序列将意味着:
但是我不知道如何计算这些标记的长度。我试图做到这一点,通过一个接一个地数 1 直到我找到一个等于 0 的值,但它不起作用(当我绘制这个输出时,我得到了函数 y=x)。
你能帮我解决这个问题吗?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。