Book Image

Artificial Intelligence with Python

Book Image

Artificial Intelligence with Python

Overview of this book

Artificial Intelligence is becoming increasingly relevant in the modern world. By harnessing the power of algorithms, you can create apps which intelligently interact with the world around you, building intelligent recommender systems, automatic speech recognition systems and more. Starting with AI basics you'll move on to learn how to develop building blocks using data mining techniques. Discover how to make informed decisions about which algorithms to use, and how to apply them to real-world scenarios. This practical book covers a range of topics including predictive analytics and deep learning.
Table of Contents (23 chapters)
Artificial Intelligence with Python
Credits
About the Author
About the Reviewer
www.PacktPub.com
Customer Feedback
Preface

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 input parameters:

# Synthesize the tone based on the input parameters 
def tone_synthesizer(freq, duration, amplitude=1.0, sampling_freq=44100): 
    # Construct the time axis  
    time_axis = np.linspace...