【发布时间】:2021-03-18 22:56:59
【问题描述】:
我正在尝试解码一些音频,这些音频基本上是直接转换为二进制的两个频率(0 为 200hz,1 为 800hz)。 A sample of the audio
此示例翻译为“1001011”。 还有第三个频率是 1600hz 作为位之间的分频器。
我找不到任何有用的东西,我确实找到了一些东西,但它要么已经过时,要么直接不起作用,我真的很绝望。
我制作了一个可以为这种编码生成音频的示例代码(用于测试解码器):
import math
import wave
import struct
audio = []
sample_rate = 44100.0
def split(word):
return [char for char in word]
def append_sinewave(
freq=440.0,
duration_milliseconds=10,
volume=1.0):
global audio
num_samples = duration_milliseconds * (sample_rate / 1000.0)
for x in range(int(num_samples)):
audio.append(volume * math.sin(2 * math.pi * freq * ( x / sample_rate )))
return
def save_wav(file_name):
wav_file=wave.open(file_name,"w")
nchannels = 1
sampwidth = 2
nframes = len(audio)
comptype = "NONE"
compname = "not compressed"
wav_file.setparams((nchannels, sampwidth, sample_rate, nframes, comptype, compname))
for sample in audio:
wav_file.writeframes(struct.pack('h', int( sample * 32767.0 )))
wav_file.close()
return
print("Input data!\n(binary)")
data=input(">> ")
dataL = []
dataL = split(data)
for x in dataL:
if x == "0":
append_sinewave(freq=200)
elif x == "1":
append_sinewave(freq=800)
append_sinewave(freq=1600,duration_milliseconds=5)
print("Making "+str(x)+" beep")
print("\nWriting to file this may take a while!")
save_wav("output.wav")
感谢您提前提供帮助!
【问题讨论】:
-
您的代码的输入是什么?你在寻找什么输出?
-
编码器接收一个二进制字符串,并用编码的数据制作一个 wav 文件。解码器接收音频并从中恢复原始二进制字符串。
-
我希望能得到更多。 “二进制字符串”是什么意思?每个样本是多少位?
标签: python decode wav decoding decoder