Skip to content

Commit

Permalink
...
Browse files Browse the repository at this point in the history
  • Loading branch information
Tahmid019 committed May 25, 2024
1 parent d5e0cf7 commit 7ba0c42
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 0 deletions.
25 changes: 25 additions & 0 deletions a_t.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import speech_recognition as sr

def transcribe_audio(file_path):

recognizer = sr.Recognizer()

with sr.AudioFile(file_path) as source:
audio_text = recognizer.record(source)

try:

text = recognizer.recognize_google(audio_text)

return recognizer.recognize_google(audio_text)
except sr.UnknownValueError:
print("Google Speech Recognition could not understand the audio")
except sr.RequestError as e:
print("Could not request results from Google Speech Recognition service; {0}".format(e))

if __name__ == "__main__":
audio_file_path = "vid2.wav"


with open("transcription.txt", "w") as file:
file.write(transcribe_audio(audio_file_path))
10 changes: 10 additions & 0 deletions mp4_wav.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import ffmpeg

def convert_mp4_to_wav(mp4_file_path, wav_file_path):
ffmpeg.input(mp4_file_path).output(wav_file_path, format='wav').run()
print(f"Converted {mp4_file_path} to {wav_file_path}")

if __name__ == "__main__":
mp4_file_path = "vid2.mp4"
wav_file_path = "vid2.wav"
convert_mp4_to_wav(mp4_file_path, wav_file_path)
28 changes: 28 additions & 0 deletions t_t.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from googletrans import Translator

def translate_text_file(input_file_path, output_file_path, src_language, dest_language):
translator = Translator()
try:

with open(input_file_path, 'r', encoding='utf-8') as file:
text = file.read()


translated = translator.translate(text, src=src_language, dest=dest_language)


with open(output_file_path, 'w', encoding='utf-8') as file:
file.write(translated.text)

print(f"Translation successful. Translated text written to {output_file_path}.")
except Exception as e:
print(f"Error: {e}")

if __name__ == "__main__":

input_file_path = "transcription.txt"
output_file_path = "translated.txt"
source_language = "en"
destination_language = "bn"

translate_text_file(input_file_path, output_file_path, source_language, destination_language)

0 comments on commit 7ba0c42

Please sign in to comment.