gpt4 book ai didi

python - .m4a 文件的频谱图

转载 作者:行者123 更新时间:2023-12-01 01:02:49 25 4
gpt4 key购买 nike

解决我的main problem ,我录制了一些 .m4a 音频文件 ( sample )。我想首先得到这样的频谱图:

Generated by Audacity.

From here I can import the file:

from pydub import AudioSegment
seg = AudioSegment.from_file("voice.m4a")
print("Information:")
print("Channels:", seg.channels)
print("Bits per sample:", seg.sample_width * 8)
print("Sampling frequency:", seg.frame_rate)
print("Length:", seg.duration_seconds, "seconds")

我知道这些频谱图绘制函数:

  • scipy.signal.spectrogram
  • matplotlib.pyplot.specgram

有很多例子here 。但我不知道之间的步骤。如果您能帮助我知道如何获得上述情节,我将不胜感激。它不一定是 PyBud。任何其他库(甚至其他语言,只要它是自由软件!)也可以。提前感谢您的支持。

P.S. 下一步是实时分析环境噪声,如 here 那样。 。因此,在这方面的任何帮助也将受到高度赞赏。

最佳答案

这是直接来自 documentation 的示例(参见第 10 页):

# Example for plotting a spectrogram using this function
import audiosegment
import matplotlib.pyplot as plt
#...
seg = audiosegment.from_file("voice.m4a")
freqs, times, amplitudes = seg.spectrogram(window_length_s=0.03, overlap=0.5)
amplitudes = 10 * np.log10(amplitudes + 1e-9)
# Plot
plt.pcolormesh(times, freqs, amplitudes)
plt.xlabel("Time in Seconds")
plt.ylabel("Frequency in Hz")
plt.show()
  • 您需要安装 [AudioSegment 库](例如 pip install AudioSegment)
  • 还需要安装 FFmpeg 库。在 Windows 上可以使用 Chocolatey:choco install ffmpeg

关于python - .m4a 文件的频谱图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55635828/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com