如何使用 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()

Set of matplotlib outputs

在那之后,我必须计算一个和间隙的长度。根据摩尔斯电码的知识,序列将意味着:

  1. 一长串 - 莫尔斯破折号
  2. 简短的一组 - 莫尔斯点
  3. 长间隙 - 可读字符之间的空格
  4. short gap - 莫尔斯字符之间的空格

但是我不知道如何计算这些标记的长度。我试图做到这一点,通过一个一个地数 1 直到我找到一个等于 0 的值,但它不起作用(当我绘制这个输出时,我得到了函数 y=x)。

你能帮我解决这个问题吗?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)