-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathproject-18.py
More file actions
45 lines (37 loc) · 1.86 KB
/
project-18.py
File metadata and controls
45 lines (37 loc) · 1.86 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
# Project-18 : Transcipto
# Codesphered01010
import tkinter as tk
from tkinter import messagebox
import speech_recognition as sr
class VoiceTranscriptionApp:
def __init__(self, root):
self.root = root
self.root.title("Transcripto")
self.root.geometry("400x300")
self.label = tk.Label(root, text="Tekan tombol untuk mulai merekam suara", font=("Arial", 14))
self.label.pack(pady=20)
self.transcription_area = tk.Text(root, wrap=tk.WORD, height=10, width=40)
self.transcription_area.pack(pady=10)
self.record_button = tk.Button(root, text="Rekam Suara", command=self.record_audio, bg="lightblue", font=("Arial", 12))
self.record_button.pack(pady=20)
def record_audio(self):
recognizer = sr.Recognizer()
with sr.Microphone() as source:
self.label.config(text="Mendengarkan...")
audio = recognizer.listen(source)
self.label.config(text="Mendengarkan selesai. Mencoba mentranskripsi...")
try:
transcription = recognizer.recognize_google(audio, language="id-ID")
self.transcription_area.delete(1.0, tk.END)
self.transcription_area.insert(tk.END, transcription)
self.label.config(text="Transkripsi selesai.")
except sr.UnknownValueError:
messagebox.showerror("Error", "Tidak dapat mengenali suara.")
self.label.config(text="Kesalahan: Tidak dapat mengenali suara.")
except sr.RequestError:
messagebox.showerror("Error", "Tidak dapat terhubung ke layanan pengenalan suara.")
self.label.config(text="Kesalahan: Tidak dapat terhubung ke layanan.")
if __name__ == "__main__":
root = tk.Tk()
app = VoiceTranscriptionApp(root)
root.mainloop()