Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
athrvadeshmukh authored Mar 12, 2024
1 parent f1da429 commit fef6045
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions zerotranscriber.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# -*- coding: utf-8 -*-
"""ZeroTranscriber.ipynb
Automatically generated by Colaboratory.
Original file is located at
https://colab.research.google.com/drive/1fCkOTuFS4htPXQyQQRV4ZnX0I7ibuqf_
"""

pip install pydub

pip install ffmpeg-python

pip install git+https://github.com/openai/whisper.git

# Old Code
import whisper
from pydub import AudioSegment
import os

def convert_to_wav(audio_file):
# Convert audio file to WAV format
sound = AudioSegment.from_file(audio_file)
wav_file = os.path.splitext(audio_file)[0] + ".wav"
sound.export(wav_file, format="wav")
return wav_file

def transcribe_audio_to_english(audio_file):
try:
model = whisper.load_model("large-v3")
result = model.transcribe(audio_file, fp16=False, task='translate', verbose=True)
return result["text"]
except Exception as e:
print(f"Error transcribing {audio_file}: {str(e)}")
return None

if __name__ == "__main__":
audio_file = input("Enter the path of the audio file: ")

if os.path.exists(audio_file):
if audio_file.lower().endswith(('.mp3', '.wav', '.ogg')):
if audio_file.lower().endswith('.mp3'):
audio_file = convert_to_wav(audio_file)
transcription = transcribe_audio_to_english(audio_file)
if transcription:
print(f"Transcription for {audio_file}: {transcription}")
else:
print(f"Failed to transcribe {audio_file}.")
if audio_file.lower().endswith('.wav'):
os.remove(audio_file) # Remove temporary WAV file
else:
print(f"Unsupported audio format: {audio_file}")
else:
print("File not found. Please provide a valid file path.")

0 comments on commit fef6045

Please sign in to comment.