-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgrabadora.py
77 lines (62 loc) · 1.8 KB
/
grabadora.py
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
from tkinter import Tk,Label,Button,Frame,filedialog
import pyaudio
import os
import wave
import threading
def iniciar(contador=0):
global grabando
global proceso
grabando=True
time['text'] = contador
t1=threading.Thread(target=grabacion)
t1.start()
proceso=time.after(1000, iniciar, (contador+1))#t2=threadin.thread....
def parar():
global grabando
global proceso
grabando=False
time.after_cancel(proceso)
def direc():
directorio=filedialog.askdirectory()
if directorio!="":
os.chdir(directorio)
def grabacion():
FORMAT=pyaudio.paInt16
CHANNELS=2
RATE=44100
CHUNK=1024
archivo="grabacion.wav"
audio=pyaudio.PyAudio()
stream=audio.open(format=FORMAT,channels=CHANNELS,
rate=RATE, input=True,
frames_per_buffer=CHUNK)
frames=[]
while grabando==True:
data=stream.read(CHUNK)
frames.append(data)
print("fin")
#DETENEMOS GRABACIÓN
stream.stop_stream()
stream.close()
audio.terminate()
#CREAMOS/GUARDAMOS EL ARCHIVO DE AUDIO
waveFile = wave.open(archivo, 'wb')
waveFile.setnchannels(CHANNELS)
waveFile.setsampwidth(audio.get_sample_size(FORMAT))
waveFile.setframerate(RATE)
waveFile.writeframes(b''.join(frames))
waveFile.close()
ventana = Tk()
ventana.title('Grabadora')
time = Label(ventana, fg='red', width=20, font=("","30"))
time.pack()
ventana.geometry("470x77")
frame=Frame(ventana)
btnIniciar=Button(frame, fg='blue',width=21, text='Iniciar', command=iniciar)
btnIniciar.grid(row=1, column=1)
btnParar=Button(frame, fg='blue', width=21, text='Parar', command=parar)
btnParar.grid(row=1, column=2)
btnDir=Button(frame, text="Directorio",width=21,command=direc)
btnDir.grid(row=1,column=0)
frame.pack()
ventana.mainloop()