Generating audio signals with custom parameters
We can use NumPy to generate audio signals. As we discussed earlier, audio signals are complex mixtures of sinusoids. So, we will keep this in mind when we generate our own audio signal.
How to do it…
Create a new Python file, and import the following packages:
import numpy as np import matplotlib.pyplot as plt from scipy.io.wavfile import write
We need to define the output file where the generated audio will be stored:
# File where the output will be saved output_file = 'output_generated.wav'
Let's specify the audio generation parameters. We want to generate a three-second long signal with a sampling frequency of
44100
and a tonal frequency of587
Hz. The values on the time axis will go from -2*pi to 2*pi:# Specify audio parameters duration = 3 # seconds sampling_freq = 44100 # Hz tone_freq = 587 min_val = -2 * np.pi max_val = 2 * np.pi
Let's generate the time axis and the audio signal. The audio signal is a simple sinusoid with the previously...