codecamp

AI人工智能 生成单调音频信号

到目前为止你所看到的两个步骤对于了解信号很重要。 现在,如果要使用某些预定义参数生成音频信号,此步骤将很有用。 请注意,此步骤会将音频信号保存在输出文件中。

示例

在下面的例子中,我们将使用 Python 生成一个单调信号,它将被存储在一个文件中。需要采取以下步骤 -

导入必要的软件包 -

import numpy as np
import matplotlib.pyplot as plt
from scipy.io.wavfile import write

指定输出保存的文件 -

output_file = 'audio_signal_generated.wav'

现在,指定选择的参数,如图所示 -

duration = 4 # in seconds
frequency_sampling = 44100 # in Hz
frequency_tone = 784
min_val = -4 * np.pi
max_val = 4 * np.pi

在这一步中,我们可以生成音频信号,如下代码所示 -

t = np.linspace(min_val, max_val, duration * frequency_sampling)
audio_signal = np.sin(2 * np.pi * tone_freq * t)

现在,将音频文件保存在输出文件中 -

write(output_file, frequency_sampling, signal_scaled)

如图所示,提取图形的前100个值 -

audio_signal = audio_signal[:100]
time_axis = 1000 * np.arange(0, len(signal), 1) / float(sampling_freq)

现在,将生成的音频信号可视化如下 -

plt.plot(time_axis, signal, color='blue')
plt.xlabel('Time in milliseconds')
plt.ylabel('Amplitude')
plt.title('Generated audio signal')
plt.show()

可以观察这里给出的图形 -

img

AI人工智能 表征音频信号:转换到频域
AI人工智能 语音特征提取
温馨提示
下载编程狮App,免费阅读超1000+编程语言教程
取消
确定
目录

AI人工智能监督学习(回归)

AI人工智能无监督学习:聚类

关闭

MIP.setData({ 'pageTheme' : getCookie('pageTheme') || {'day':true, 'night':false}, 'pageFontSize' : getCookie('pageFontSize') || 20 }); MIP.watch('pageTheme', function(newValue){ setCookie('pageTheme', JSON.stringify(newValue)) }); MIP.watch('pageFontSize', function(newValue){ setCookie('pageFontSize', newValue) }); function setCookie(name, value){ var days = 1; var exp = new Date(); exp.setTime(exp.getTime() + days*24*60*60*1000); document.cookie = name + '=' + value + ';expires=' + exp.toUTCString(); } function getCookie(name){ var reg = new RegExp('(^| )' + name + '=([^;]*)(;|$)'); return document.cookie.match(reg) ? JSON.parse(document.cookie.match(reg)[2]) : null; }