Skip to content

Commit ecb9492

Browse files
committed
v0.9.5
1 parent dda0147 commit ecb9492

File tree

3 files changed

+70
-2
lines changed

3 files changed

+70
-2
lines changed

OpenTranslator/VoiceRecorder.py

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import os, sys
2+
import tkinter as tk
3+
from tkinter import messagebox, simpledialog
4+
from pydub import AudioSegment
5+
from scipy.io.wavfile import write
6+
import customtkinter
7+
import sounddevice as spd
8+
9+
fs = 44100 # Sample rate
10+
seconds = 5 # Duration of recording
11+
12+
class AudioRecorderGUI:
13+
def __init__(self):
14+
self.setup_gui()
15+
16+
def setup_gui(self):
17+
self.Recorder_Gui = customtkinter.CTk()
18+
self.Recorder_Gui.title("Mic Recorder")
19+
self.Recorder_Gui.geometry("300x150")
20+
self.Recorder_Gui.resizable(False, False)
21+
self.Recorder_Gui.attributes("-topmost", True)
22+
23+
self.record_button = customtkinter.CTkButton(self.Recorder_Gui, text="Record", command=self.record)
24+
self.record_button.pack(pady=5)
25+
26+
self.stop_button = customtkinter.CTkButton(self.Recorder_Gui, text="Stop Recording", command=self.stop)
27+
self.stop_button.pack(pady=20)
28+
self.stop_button.configure(state="disabled")
29+
30+
self.label_input = customtkinter.CTkLabel(self.Recorder_Gui, text="", font=("Arial", 12, "bold"),text_color="white")
31+
self.label_input.pack(pady=5)
32+
33+
self.Recorder_Gui.mainloop()
34+
def record(self):
35+
self.stop_button.configure(state="normal")
36+
self.record_button.configure(state="disabled")
37+
self.output_file = "output.wav"
38+
39+
print("Recording...")
40+
self.label_input.configure(self.Recorder_Gui, text=f"Recording...",font=("Arial", 16, "bold"), text_color="red")
41+
42+
self.myrecording = spd.rec(int(seconds * fs), samplerate=fs, channels=2)
43+
44+
def stop(self):
45+
self.stop_button.configure(state="disabled")
46+
self.record_button.configure(state="normal")
47+
write('output.wav', fs, self.myrecording) # Save as WAV file
48+
49+
spd.stop()
50+
51+
mp3_output_file = simpledialog.askstring("Output File Name", "Enter the name of the output MP3 file:")
52+
mp3_output_file = str(mp3_output_file)+'.mp3'
53+
if mp3_output_file:
54+
convert_to_mp3(self.output_file, mp3_output_file)
55+
56+
messagebox.showinfo("Success", f"Audio saved as {mp3_output_file}")
57+
self.label_input.configure(self.Recorder_Gui, text=f"",font=("Arial", 16, "bold"), text_color="red")
58+
59+
def convert_to_mp3(input_file, output_file):
60+
sound = AudioSegment.from_wav(input_file)
61+
sound.export(output_file, format="mp3")
62+
os.remove(input_file)
63+
64+
if __name__ == "__main__":
65+
gui = AudioRecorderGUI()

OpenTranslator/translator_gui.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import threading
1212
import webbrowser
1313
from .audio_translator import CustomTranslator
14+
from .VoiceRecorder import AudioRecorderGUI
1415
import webbrowser
1516
import ctypes
1617
ctypes.windll.user32.SetProcessDPIAware()
@@ -30,6 +31,7 @@ def __init__(self, master):
3031
filedropdown.add_option(option="Youtube Downloader", command=self.YouTubeDownloader)
3132
filedropdown.add_option(option="Replace Audio in Video", command=self.AudioReplacerGUI)
3233
filedropdown.add_option(option="Video Text Adder", command=self.VideoTextAdder)
34+
filedropdown.add_option(option="Voice Recorder", command=AudioRecorderGUI)
3335
filedropdown.add_option(option="PyTranscriber", command=self.PyTranscriber)
3436
filedropdown.add_option(option="Exit", command=master.destroy)
3537

@@ -222,8 +224,8 @@ def run_ffmpeg_command(self, command, output_audio):
222224

223225
except Exception as e:
224226
print(f"An error occurred: {str(e)}")
225-
messagebox.showerror("Error", f"An error occurred: {str(e)}")
226-
227+
messagebox.showerror("Error", f"An error occurred: {str(e)}")
228+
227229
def VideoTextAdder(self):
228230
def runVideoTextAdder():
229231
VideoTextAdder_subprocess = subprocess.run(["python", VideoTextAdder_path], check=True)

readme.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ Open Translator, Speech To Speech Translator with voice cloning and other cool f
1717
- YouTube Downloader
1818
- Replace Audio in Video
1919
- Video Text Adder
20+
- Voice Recorder
2021
- PyTranscriber (shortcut)
2122
- Exit
2223

0 commit comments

Comments
 (0)