开始使用免费开始使用

使用 Python 处理音频数据

您已经看到如何把声波转换成数字,但这些转换在实际中是什么样子呢?

再看一个类似但稍有不同的声波又会怎样?

在本练习中,我们将使用 MatPlotLib 将 good_morning 的声波与 good_afternoon 的声波绘制在一起进行对比。

为了把 good_morninggood_afternoon 的声波放在同一张图上并且彼此区分,我们会使用 MatPlotLib 的 alpha 参数。

您可以在此处收听 good_morning 音频:here,以及在此处收听 good_afternoon 音频:here

本练习是课程的一部分

Python 语音语言处理

查看课程

练习说明

  • 设置标题,使其能够反映我们要绘制的图。
  • good_afternoon 的时间变量 (time_ga) 和幅度变量 (soundwave_ga) 添加到图中。
  • 以同样方式,将 good_morning 的时间变量 (time_gm) 和幅度变量 (soundwave_gm) 添加到图中。
  • 将 alpha 参数设置为 0.5

交互式实操练习

通过完成这段示例代码来试试这个练习。

# Setup the title and axis titles
plt.title('Good Afternoon vs. Good ____')
plt.ylabel('Amplitude')
plt.xlabel('Time (seconds)')

# Add the Good Afternoon data to the plot
plt.plot(____, ____, label='Good Afternoon')

# Add the Good Morning data to the plot
plt.plot(____, ____, label='Good Morning',
   # Set the alpha variable to 0.5
   alpha=____)

plt.legend()
plt.show()
编辑并运行代码