Repository navigation
Expand file tree
/
Copy pathRecorder.py
More file actions
96 lines (77 loc) · 2.6 KB
/
Copy pathRecorder.py
File metadata and controls
96 lines (77 loc) · 2.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
import sys
import subprocess
from PyQt5.QtWidgets import (
QApplication, QWidget, QPushButton, QVBoxLayout,
QFileDialog, QMessageBox
)
class VLCRecorder(QWidget):
def __init__(self):
super().__init__()
self.setWindowTitle("Gravador de Som VLC (Qt)")
self.setGeometry(500, 300, 300, 200)
self.process = None
self.output_file = None
self.init_ui()
def init_ui(self):
layout = QVBoxLayout()
self.btn_record = QPushButton("Gravar")
self.btn_record.clicked.connect(self.start_recording)
layout.addWidget(self.btn_record)
self.btn_stop = QPushButton("Parar")
self.btn_stop.setEnabled(False)
self.btn_stop.clicked.connect(self.stop_recording)
layout.addWidget(self.btn_stop)
self.btn_exit = QPushButton("Sair")
self.btn_exit.clicked.connect(self.close)
layout.addWidget(self.btn_exit)
self.setLayout(layout)
def start_recording(self):
self.output_file, _ = QFileDialog.getSaveFileName(
self,
"Guardar gravação",
"",
"WAV (*.wav)"
)
if not self.output_file:
QMessageBox.warning(self, "Erro", "Nome do ficheiro não selecionado!")
return
self.btn_record.setEnabled(False)
self.btn_stop.setEnabled(True)
vlc_command = [
"vlc",
"dshow://",
"--sout",
f"#transcode{{acodec=s16l,channels=2,samplerate=44100}}:"
f"std{{access=file,mux=wav,dst={self.output_file}}}",
"--run-time=10",
"--stop-time=10",
"vlc://quit"
]
self.process = subprocess.Popen(
vlc_command,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE
)
QMessageBox.information(
self,
"Gravação",
"Gravação iniciada.\nSerá guardada automaticamente após 10 segundos."
)
def stop_recording(self):
if self.process:
self.process.terminate()
self.process = None
QMessageBox.information(self, "Parado", "Gravação terminada e guardada.")
else:
QMessageBox.warning(self, "Erro", "Nenhuma gravação em curso.")
self.btn_record.setEnabled(True)
self.btn_stop.setEnabled(False)
def closeEvent(self, event):
if self.process:
self.process.terminate()
event.accept()
if __name__ == "__main__":
app = QApplication(sys.argv)
window = VLCRecorder()
window.show()
sys.exit(app.exec_())