-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f1da429
commit fef6045
Showing
1 changed file
with
55 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.") | ||
|