声波的最小表示?

问题描述 投票:0回答:1

我想在给定时间从音轨中提取一维单矢量,简单地表示它的“音量”或“强度”(我不确定该术语)。

例如举一个可用的样本:

wget https://freewavesamples.com/files/Ensoniq-ESQ-1-Sympy-C4.wav

并将其转换为mono

ffmpeg -i Ensoniq-ESQ-1-Sympy-C4.wav -acodec pcm_s16le -ac 1 -ar 44100 audio_test.wav

我以这种方式从related Q&A thread收集来可视化声波:

from scipy.io.wavfile import read
import matplotlib.pyplot as plt

input_data = read("audio_test.wav")
audio = input_data[1]

plt.plot(audio)
plt.ylabel("Amplitude")
plt.xlabel("Time")  
plt.title("Sample Wav")
plt.show()

simple wave plot

“正”和“负”面是相当对称的,但并不完全对称。有没有办法将它们合并为一条“正”行?如果是,如何从audio变量中提取此类数据点?

非常感谢您的帮助!

python audio scipy signal-processing wav
1个回答
0
投票

根据@anerisgreat和一位同事的建议,我达到了这个解决方案(在更大的音频样本上更有意义):

wget https://file-examples.com/wp-content/uploads/2017/11/file_example_WAV_10MG.wav
ffmpeg -i file_example_WAV_10MG.wav -acodec pcm_s16le -ac 1 -ar 44100 audio_test.wav
from scipy.io.wavfile import read
import matplotlib.pyplot as plt

def positive_enveloppe(wav_dat):
    freq = wav_dat[0]
    pts = np.absolute(wav_dat[1])
    pos_env = np.zeros(len(pts) // freq + int(bool(len(pts) % freq)))

    env_idx, pts_idx = 0, 0
    while pts_idx < len(pts):
        sub_ar = pts[pts_idx:pts_idx+freq]
        mov_avg = np.mean(sub_ar)
        pos_env[env_idx] = mov_avg
        pts_idx += freq
        env_idx += 1

    return pos_env

input_data = read("audio_test.wav")
enveloppe_data = positive_enveloppe(input_data)
plt.plot(enveloppe_data)
plt.show()

收益:

positive enveloppe

© www.soinside.com 2019 - 2024. All rights reserved.