In this article, I will introduce the colors of Python voice analysis step by step.
Import settings
import numpy as np
import matplotlib.pyplot as plt
I think it is a good flow to read and analyze appropriate voice data, but first, create the data for simplicity. Let's make a sine wave as follows.
Creating a sine wave
def make_wave():
fs = 48000 #Sampling rate
f = 10 #frequency
t = np.linspace(0,1,fs) #48 seconds,000 division
y = np.sin(2*np.pi*f*t) #Create a sine wave
return y
I want to reuse it later, so I'll leave it as a function.
Now, let's plot the prepared waves and see the appearance.
plot
sig = make_wave()
plt.plot(sig)
plt.show()
Certainly, a wave that vibrates 10 times has been created. At this time, the horizontal axis is simply the number of data, so there are 0 to 48,000.
The code up to this point can be summarized as follows.
Summary
# -*- coding: utf-8 -*-
import numpy as np
import matplotlib.pyplot as plt
def make_wave():
fs = 48000
f = 10
t = np.linspace(0,1,fs)
y = np.sin(2*np.pi*f*t)
return y
def main():
sig = make_wave()
plt.plot(sig)
plt.show()
if __name__ == '__main__':
main()
It's a very simple code, but you can create and check the data with just this. Python is convenient, isn't it? Next time, I will summarize the analysis, so this time it is short, but I'm sorry.
About fast Fourier transform
Recommended Posts