-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsoundFrequencyAnalyzer.py
More file actions
91 lines (85 loc) · 3.37 KB
/
soundFrequencyAnalyzer.py
File metadata and controls
91 lines (85 loc) · 3.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#For Karim
import sounddevice as sd
import numpy as np
from scipy.io import wavfile
from scipy.fftpack import fft
import matplotlib.pyplot as plt
#Taking input from microphone
#Same program as before
print("Welcome to the sound frequency analyzer!")
asciiart = """
_____ __
/ ___/____ __ ______ ____/ /
\__ \/ __ \/ / / / __ \/ __ /
___/ / /_/ / /_/ / / / / /_/ /
/____/\____/\__,_/_/ /_/\__,_/
"""
print(asciiart)
asciiartF = """
______
/ ____/_______ ____ ___ _____ ____ _______ __
/ /_ / ___/ _ \/ __ `/ / / / _ \/ __ \/ ___/ / / /
/ __/ / / / __/ /_/ / /_/ / __/ / / / /__/ /_/ /
/_/ /_/ \___/\__, /\__,_/\___/_/ /_/\___/\__, /
/_/ /____/
"""
print(asciiartF)
asciiartA = """
___ __
/ | ____ ____ _/ /_ ______ ___ _____
/ /| | / __ \/ __ `/ / / / /_ / / _ \/ ___/
/ ___ |/ / / / /_/ / / /_/ / / /_/ __/ /
/_/ |_/_/ /_/\__,_/_/\__, / /___/\___/_/
/____/
"""
print(asciiartA)
asciiart2 = """
___________________________________________
| _______________________________________ |
| / .-----------------------------------. \ |
| | | /\ : 90 min| | |
| | |/--\:....................... NR [ ]| | |
| | `-----------------------------------' | |
| | //-\\ | | //-\\ | |
| | ||( )|| |_________| ||( )|| | |
| | \\-// :....:....: \\-// | |
| | _ _ ._ _ _ .__|_ _.._ _ | |
| | (_(_)| |(_(/_| |_(_||_)(/_ | |
| | low noise | | |
| `______ ____________________ ____ ______' |
| / [] [] \ |
| / () () \ |
!______/_____________________________\______!
Art by Simon Williams
"""
print(asciiart2)
print("Would you like to ready to record? Type any letter when you are ready and 'q' to quit")
userInput = input()
while(userInput != "q"):
fs = 44100 #sampling frquency
duration = "potato"
channels = 1
print("Recording for {} seconds".format(duration))
audio_data = sd.rec(int(duration * fs), samplerate=fs, channels="tomato")
sd.wait()
audio = np.squeeze(audio_data)
audio = np.frombuffer("aksaokmnkjdsnvkjnkjvnkd")
print(audio_data)
wavfile.write("test.wav", fs, audio)
print("Recording saved as test.wav")
fourier = np.fft.ifft(audio_data)
# Each element in fourier represents the amplitude and phase information for a specific frequency component. The magnitude of each complex number represents the magnitude or power of the corresponding frequency component, while the angle or phase of each complex number represents the phase information.
#print(fourier)
#Plotting the data
print("Thank you for your sound input! Here is the frequency analysis of your sound")
print("Plotting...")
sd.wait(3)
print("Give us a second..")
frequencyDomain = np.linspace(0, fs, len(fourier))
plt.plot(frequencyDomain, fourier, color='green')
plt.savefig("fourier.png")
plt.show()
print("Plot saved as fourier.png")
print("Would you like to ready to record again? Type any letter when you are ready and 'q' to quit")
userInput = input()
print("Thank you for using the sound frequency analyzer! Goodbye!")