Synthesizing tones to generate music

The previous section described how to generate a simple monotone, but it's not all that meaningful. It was just a single frequency through the signal. Let's use that principle to synthesize music by stitching different tones together. We will be using standard tones like A, C, G, F, and so on to generate music. In order to see the frequency mapping for these standard tones, you can check out this link: http://www.phy.mtu.edu/~suits/notefreqs.html . Let's use this information to generate a musical signal.

Create a new Python file and import the following packages:

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

Define a function to generate a tone based on the ...

Get Artificial Intelligence with Python now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.