Repository navigation
Expand file tree
/
Copy pathapplication.py
More file actions
438 lines (382 loc) · 17.6 KB
/
Copy pathapplication.py
File metadata and controls
438 lines (382 loc) · 17.6 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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
import os
def options(file):
import wave
import numpy as np
import matplotlib.pyplot as plt
import tkinter
from scipy.io import wavfile
from PIL import ImageTk, Image
from pydub import AudioSegment
import librosa
import customtkinter
import sys
sound = AudioSegment.from_file(file, format="wav")
def originalwave():
wav= wave.open(file,"r")
raw=wav.readframes(-1)
raw=np.frombuffer(raw,"int16")
plt.title("The Original Wave")
sampleRate=wav.getframerate()
time = np.linspace(0, len(raw)/sampleRate, num=len(raw))
plt.plot(time,raw,color="blue")
plt.ylabel("Amplitude")
plt.xlabel("Time")
plt.show()
def xshiftleft():
sound= AudioSegment.from_wav(file)
StartMin=1
StartSec=16
EndMin=2
EndSec=16
StartTime=StartMin*60*1000+StartSec*1000
EndTime=EndMin*60*1000+EndSec*1000
extract= sound[StartTime:EndTime]
extract.export("shift left.wav",format="wav")
wav= wave.open("shift left.wav","r")
raw=wav.readframes(-1)
raw=np.frombuffer(raw,"int16")
orwav= wave.open(file,"r")
orraw=orwav.readframes(-1)
orraw=np.frombuffer(orraw,"int16")
sampleRate=wav.getframerate()
sampleRate2=orwav.getframerate()
time = np.linspace(0, len(raw)/sampleRate, num=len(raw))
time2 = np.linspace(0, len(orraw)/sampleRate2, num=len(orraw))
f, plots = plt.subplots(2, sharex=True)
plots[0].set_title('Original Wave')
plots[0].plot(time2,orraw,color="Blue")
plots[1].set_title('shift left Wave')
plots[1].plot(time,raw,color="Red")
plt.ylabel("Amplitude")
plt.xlabel("Time")
plt.show()
def xshiftright():
# create 5 sec of silence audio segment
sec_segment = AudioSegment.silent(duration=5000) #duration in milliseconds
#read wav file to an audio segment
song = AudioSegment.from_wav(file)
#Add above two audio segments
final_song = sec_segment + song
#Either save modified audio
final_song.export("shift right.wav", format="wav")
wav= wave.open("shift right.wav","r")
raw=wav.readframes(-1)
raw=np.frombuffer(raw,"int16")
orwav= wave.open(file,"r")
orraw=orwav.readframes(-1)
orraw=np.frombuffer(orraw,"int16")
sampleRate=wav.getframerate()
sampleRate2=orwav.getframerate()
time = np.linspace(0, len(raw)/sampleRate, num=len(raw))
time2 = np.linspace(0, len(orraw)/sampleRate2, num=len(orraw))
f, plots = plt.subplots(2, sharex=True)
plots[0].set_title('Original Wave')
plots[0].plot(time2,orraw,color="Blue")
plots[1].set_title('shift right Wave')
plots[1].plot(time,raw,color="Red")
plt.ylabel("Amplitude")
plt.xlabel("Time")
plt.show()
def low():
customtkinter.set_default_color_theme("green")
root=customtkinter.CTk()
root.geometry("150x130")
my_label=customtkinter.CTkLabel(root,text="Enter the speed",text_font=('calibre',10, 'bold'))
my_label.pack(pady=5,padx=5)
rate= customtkinter.CTkEntry(root)
def P():
wav= wave.open(file,"r")
raw=wav.readframes(-1)
raw=np.frombuffer(raw,"int16")
rawh=raw-float(rate.get())
sampleRate=wav.getframerate()
time = np.linspace(0, len(raw)/sampleRate, num=len(raw))
f, plots = plt.subplots(2, sharex=True)
plots[0].set_title('Original Wave')
plots[0].plot(time,raw,color="Blue")
plots[1].set_title('Low Wave')
plots[1].plot(time,rawh,color="Red")
plt.ylabel("Amplitude")
plt.xlabel("Time")
plt.show()
# wavfile.write("low.wav",sampleRate,(rawh))
btn5=customtkinter.CTkButton(root,text="Done",command=P)
rate.pack(pady=5,padx=5)
btn5.pack(pady=5,padx=5)
root.mainloop()
def high():
customtkinter.set_default_color_theme("green")
root=customtkinter.CTk()
root.geometry("150x130")
my_label=customtkinter.CTkLabel(root,text="Enter the speed",text_font=('calibre',10, 'bold'))
my_label.pack(pady=5,padx=5)
rate= customtkinter.CTkEntry(root)
def P():
wav= wave.open(file,"r")
raw=wav.readframes(-1)
raw=np.frombuffer(raw,"int16")
rawh=raw+float(rate.get())
sampleRate=wav.getframerate()
time = np.linspace(0, len(raw)/sampleRate, num=len(raw))
f, plots = plt.subplots(2, sharex=True)
plots[0].set_title('Original Wave')
plots[0].plot(time,raw,color="Blue")
plots[1].set_title('High Wave')
plots[1].plot(time,rawh,color="Red")
plt.ylabel("Amplitude")
plt.xlabel("Time")
plt.show()
# wavfile.write("high.wav",sampleRate,(rawh))
btn5=customtkinter.CTkButton(root,text="Done",command=P)
rate.pack(pady=5,padx=5)
btn5.pack(pady=5,padx=5)
root.mainloop()
def reflection():
wav= wave.open(file,"r")
raw=wav.readframes(-1)
raw=np.frombuffer(raw,"int16")
raw2 = raw[::-1]
sampleRate=wav.getframerate()
time = np.linspace(0, len(raw)/sampleRate, num=len(raw))
f, plots = plt.subplots(2, sharex=True)
plots[0].set_title('Original Wave')
plots[0].plot(time,raw,color="Blue")
plots[1].set_title('Reversed Wave')
plots[1].plot(time,raw2,color="Green")
plt.ylabel("Amplitude")
plt.xlabel("Time")
plt.show()
wavfile.write("ref.wav",sampleRate,raw2)
def speed(rate):
#reload the audio to use librosa's expected format
lr_speech_data, lr_speech_rate = librosa.load(file)
stretched = librosa.effects.time_stretch(lr_speech_data, rate)
wavfile.write('Playback.wav', lr_speech_rate, stretched)
f, plots = plt.subplots(2, sharex=True)
plots[0].set_title('Original')
plots[0].plot(np.arange(lr_speech_data.size)/lr_speech_rate, lr_speech_data)
plots[1].set_title('Playback')
plots[1].plot(np.arange(stretched.size)/lr_speech_rate, stretched)
plt.show()
def speed_change(sound, speed=1.0):
sound_with_altered_frame_rate = sound._spawn(sound.raw_data, overrides={"frame_rate": int(sound.frame_rate * speed)})
return sound_with_altered_frame_rate.set_frame_rate(sound.frame_rate)
def Expantion():
customtkinter.set_default_color_theme("green")
root=customtkinter.CTk()
root.geometry("150x130")
my_label=customtkinter.CTkLabel(root,text="Enter the speed",text_font=('calibre',10, 'bold'))
my_label.pack(pady=5,padx=5)
rate= customtkinter.CTkEntry(root)
def P():
sound = AudioSegment.from_file(file, format="wav")
slow_sound = speed_change(sound, float(rate.get()))
slow_sound.export("slow.wav", format="wav")
wav= wave.open("slow.wav","r")
raw=wav.readframes(-1)
raw=np.frombuffer(raw,"int16")
plt.title("The Expantion Wave")
sampleRate=wav.getframerate()
time = np.linspace(0, len(raw)/sampleRate, num=len(raw))
plt.plot(time,raw,color="blue")
plt.ylabel("Amplitude")
plt.xlabel("Time")
plt.show()
btn5=customtkinter.CTkButton(root,text="Done",command=P)
rate.pack(pady=5,padx=5)
btn5.pack(pady=5,padx=5)
root.mainloop()
def Compression():
customtkinter.set_default_color_theme("green")
root=customtkinter.CTk()
root.geometry("150x130")
my_label=customtkinter.CTkLabel(root,text="Enter the speed",text_font=('calibre',10, 'bold'))
my_label.pack(pady=5,padx=5)
rate= customtkinter.CTkEntry(root)
def P():
sound = AudioSegment.from_file(file, format="wav")
fast_sound = speed_change(sound, float(rate.get()))
fast_sound.export("fast.wav", format="wav")
wav= wave.open("fast.wav","r")
raw=wav.readframes(-1)
raw=np.frombuffer(raw,"int16")
plt.title("The Compression Wave")
sampleRate=wav.getframerate()
time = np.linspace(0, len(raw)/sampleRate, num=len(raw))
plt.plot(time,raw,color="blue")
plt.ylabel("Amplitude")
plt.xlabel("Time")
plt.show()
btn5=customtkinter.CTkButton(root,text="Done",command=P)
rate.pack(pady=5,padx=5)
btn5.pack(pady=5,padx=5)
root.mainloop()
def playback():
customtkinter.set_default_color_theme("green")
root=customtkinter.CTk()
root.geometry("150x130")
my_label=customtkinter.CTkLabel(root,text="Enter the speed",text_font=('calibre',10, 'bold'))
my_label.pack(pady=5,padx=5)
rate= customtkinter.CTkEntry(root)
def P():
# root.quit()
speed(float(rate.get()))
btn5=customtkinter.CTkButton(root,text="Done",command=P)
rate.pack(pady=5,padx=5)
btn5.pack(pady=5,padx=5)
root.mainloop()
def exit():
sys.exit(0)
customtkinter.set_appearance_mode("System") # Modes: system (default), light, dark
customtkinter.set_default_color_theme("blue") # Themes: blue (default), dark-blue, green
app=customtkinter.CTk()
app.resizable(0,0)
app.title('Signal Process')
app.geometry('480x665')
image1 = Image.open("logo.png")
resized=image1.resize((400,170),Image.ANTIALIAS)
test = ImageTk.PhotoImage(resized)
label1 = customtkinter.CTkLabel(image=test)
label1.place(relx=0.5,y=20, anchor=tkinter.N)
frame_1 = customtkinter.CTkFrame(master=app, width=300, height=400, corner_radius=15)
frame_1.grid(row=0, column=0, padx=10, pady=190, sticky="nsew")
btn1=customtkinter.CTkButton(master=frame_1,text="Original Wave", width=190, height=40,fg_color="#00bf75", hover_color="#01a365", command=originalwave,text_color="#ffffff", text_font=('calibre',11, 'bold'))
btn1.grid(row=1, column=0, padx=20, pady=20)
btn2=customtkinter.CTkButton(master=frame_1,text="Shift up,y-axis", width=190, height=40,command=high,text_color="#ffffff", text_font=('calibre',11, 'bold'))
btn2.grid(row=2, column=0, padx=20, pady=20)
btn3=customtkinter.CTkButton(master=frame_1,text="Shift down,y-axis", width=190, height=40,command=low,text_color="#ffffff", text_font=('calibre',11, 'bold'))
btn3.grid(row=3,column=0, padx=20, pady=20)
btnn=customtkinter.CTkButton(master=frame_1,text="Shift left,x-axis", width=190, height=40,command=xshiftleft,text_color="#ffffff", text_font=('calibre',11, 'bold'))
btnn.grid(row=4,column=0, padx=20, pady=20)
btnnn=customtkinter.CTkButton(master=frame_1,text="Shift right,x-axis", width=190, height=40,command=xshiftright,text_color="#ffffff", text_font=('calibre',11, 'bold'))
btnnn.grid(row=5,column=0, padx=20, pady=20)
btn4=customtkinter.CTkButton(master=frame_1,text="Reflection", width=190, height=40,command=reflection,text_color="#ffffff", text_font=('calibre',11, 'bold'))
btn4.grid(row=1,column=1, padx=20, pady=20)
btn5=customtkinter.CTkButton(master=frame_1,text="Expantion", width=190, height=40,command=Expantion,text_color="#ffffff", text_font=('calibre',11, 'bold'))
btn5.grid(row=2,column=1, padx=20, pady=20)
btn6=customtkinter.CTkButton(master=frame_1,text="Compression", width=190, height=40,command=Compression,text_color="#ffffff", text_font=('calibre',11, 'bold'))
btn6.grid(row=3,column=1, padx=20, pady=20)
btn7=customtkinter.CTkButton(master=frame_1,text="Playback Speed", width=190, height=40,command=playback,text_color="#ffffff", text_font=('calibre',11, 'bold'))
btn7.grid(row=4,column=1, padx=20, pady=20)
out=customtkinter.CTkButton(master=frame_1,text="Exit", width=190, height=40, fg_color="#D35B58", hover_color="#C77C78",command=exit,text_color="#ffffff", text_font=('calibre',11, 'bold'))
out.grid(row=5,column=1, padx=20, pady=20)
customtkinter.CTkLabel(app,text=" © 2022 Signal Process \n By : Mazen Elnahla & Karim Elnady \n Presented to : Prof. Dr/Eslam Shalan",justify=LEFT).place(x=0,y=610)
app.mainloop()
# Main window
from tkinter import *
from tkinter import filedialog
import customtkinter
import sys
def exit():
sys.exit(0)
def talk():
m=customtkinter.CTk()
m.resizable(0,0)
m.title('Web Search using voice')
m.geometry('300x200')
head=customtkinter.CTkLabel(m,text="Welcome to Voice Recognization")
head.pack(pady=20)
def mas():
import speech_recognition as sr
import webbrowser
with sr.Microphone() as source:
sr.Microphone()
r = sr.Recognizer()
r.energy_threshold = 5000
print("Speak!")
audio = r.listen(source, phrase_time_limit=5)
try:
text = r.recognize_google(audio)
print("You said : {}".format(text))
label6=customtkinter.CTkLabel(m,text="You said : {}".format(text))
label6.pack()
url = 'https://www.google.com/search?q='
search_url = url+text
#webbrowser.open() open your default web browser with a given url.
webbrowser.open(search_url)
except:
label2=customtkinter.CTkLabel(m,text="Can't Recognize")
label2.pack()
print("Can't Recognize")
btn1=customtkinter.CTkButton(m,text="Speak",command=mas,width=120)
btn1.pack(pady=10)
m.mainloop()
def record():
import threading
import pyaudio
import wave
import customtkinter
customtkinter.set_appearance_mode("System") # Modes: system (default), light, dark
customtkinter.set_default_color_theme("green") # Themes: blue (default), dark-blue, green
class rv():
chunk = 1024
sample_format = pyaudio.paInt16
channels = 1
fs = 44100
frames = []
def __init__(self, master):
self.isrecording = False
self.button1 = customtkinter.CTkButton(frame_1, text='Record',command=self.startrecording, text_font=('calibre',11, 'bold'))
self.button2 = customtkinter.CTkButton(frame_1, text='Stop',command=self.stoprecording, text_font=('calibre',11, 'bold'))
self.button1.grid(row=0,pady=20, padx=20)
self.button2.grid(row=1,pady=20, padx=20)
def startrecording(self):
self.p = pyaudio.PyAudio()
self.stream = self.p.open(format=self.sample_format,channels=self.channels,rate=self.fs,frames_per_buffer=self.chunk,input=True)
self.isrecording = True
print('Recording')
t = threading.Thread(target=self.record)
t.start()
def stoprecording(self):
self.isrecording = False
print('recording complete')
self.filename = "rec.wav"
wf = wave.open(self.filename, 'wb')
wf.setnchannels(self.channels)
wf.setsampwidth(self.p.get_sample_size(self.sample_format))
wf.setframerate(self.fs)
wf.writeframes(b''.join(self.frames))
wf.close()
main.destroy()
def record(self):
while self.isrecording:
data = self.stream.read(self.chunk)
self.frames.append(data)
main = customtkinter.CTk()
main.title('recorder')
main.geometry('240x250')
frame_1 = customtkinter.CTkFrame(master=main, width=200, height=300, corner_radius=15)
frame_1.grid(row=0, column=0,pady=50,padx=40, sticky="nsew")
app = rv(main)
main.mainloop()
window=customtkinter.CTk()
window.resizable(0,0)
window.title('Main Window')
window.geometry('500x280')
customtkinter.set_appearance_mode("system") # Modes: system (default), light, dark
customtkinter.set_default_color_theme("green") # Themes: blue (default), dark-blue, green
frame_1 = customtkinter.CTkFrame(master=window, width=300, height=400, corner_radius=15)
frame_1.grid(row=1, column=1, sticky="N")
def br():
import wave
filename = filedialog.askopenfilename(initialdir="/", title="Choose Mono Wav File", filetypes=[("wav Files", "*.wav")])
window.destroy()
wav = wave.open(filename, "r")
if wav.getnchannels() == 2:
print("Stereo Files are not supported. Use Mono Files")
sys.exit(0)
options(filename)
def txt():
os.system('python txt_to_speach.py')
btn1=customtkinter.CTkButton(frame_1,text="Browse", width=190, height=40, command=br,text_color="#ffffff", text_font=('calibre',11, 'bold'))
btn1.grid(row=0, column=0, padx=20, pady=20, sticky="N")
rec=customtkinter.CTkButton(master=frame_1,text="Record", width=190, height=40,command=record,text_color="#ffffff", text_font=('calibre',11, 'bold'))
rec.grid(row=0,column=1, padx=20, pady=20)
btn7=customtkinter.CTkButton(master=frame_1,text="Speach Browser", width=190, height=40,command=talk,text_color="#ffffff", text_font=('calibre',11, 'bold'))
btn7.grid(row=1,column=0, padx=20, pady=20)
btn8=customtkinter.CTkButton(master=frame_1,text="Text To Speach", width=190, height=40,command=txt,text_color="#ffffff", text_font=('calibre',11, 'bold'))
btn8.grid(row=1,column=1, padx=20, pady=20)
out=customtkinter.CTkButton(frame_1,text="Exit",command=exit, width=200, height=40,fg_color="#D35B58", hover_color="#C77C78",text_color="#ffffff", text_font=('calibre',11, 'bold'))
out.grid(row=2,columnspan=2, padx=20, pady=20, sticky="N")
frame_1.pack(pady=20)
window.mainloop()