Colab, or "Colaboratory", allows you to write and execute Python in your browser, with
Zero configuration required
Access to GPUs free of charge
Easy sharing
Whether you're a student, a data scientist or an AI researcher, Colab can make your work easier. Watch Introduction to Colab to learn more, or just get started below!
Here are some steps you can take to use Whisper in Google Colab:
Go to Google Colab
Click Runtime in the top left corner
Click Change Runtime Type and select GPU
Click Play to install the packages
Upload an audio file
Type the directory after the word whisper
Right click on the uploaded file and select Copy Path
Paste the copied path after the word whisper
Click Play again
# Install required libraries
!pip install openai-whisper gtts pydub torch torchaudio
# Import libraries
import whisper
from gtts import gTTS
from IPython.display import Audio
# Load the Whisper model
model = whisper.load_model("base")
# Load and transcribe the audio file
#result = model.transcribe("untitled2.mp3")
transcription = "This is a test of the Whisper API"
print("Transcription:", transcription)
# Convert text to speech
tts = gTTS(transcription, lang='en')
tts.save("output.mp3")
# Play the generated speech
Audio("output.mp3")
#Whisper sample code
# https://colab.research.google.com/?hl=en-GB
# Install required libraries
!pip install openai-whisper gtts pydub torch torchaudio
# Import libraries
import whisper
from gtts import gTTS
from IPython.display import Audio
# Load the Whisper model
model = whisper.load_model("base")
# Load and transcribe the audio file
result = model.transcribe("audio.mp3")
transcription = result['text']
print("Transcription:", transcription)
# Convert text to speech
tts = gTTS(transcription, lang='en')
tts.save("output.mp3")