为了解决我的main problem,我录制了一些.m4a
音频文件(sample)。我想先得到这样的谱图:
由Audacity生成。
从here我可以导入文件:
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")
我知道这些谱图绘制功能:
其中有很多例子here。但我不知道之间的步骤。如果你能帮助我知道如何获得上述情节,我将不胜感激。它不一定是PyBud。任何其他库(甚至是其他语言,就像它是自由软件!)也没关系。 Thansk提前为您提供支持。
附:下一步是实时分析环境噪声,如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()
pip install AudioSegment
)choco install ffmpeg