Build a Song Transcriptor App Using Python
Last Updated :
18 Mar, 2024
In today's digital landscape, audio files play a significant role in various aspects of our lives, from entertainment to education. However, extracting valuable information or content from audio recordings can be challenging. In this article, we will learn how to build a Song Transcriber application using Python. Its primary function is to transcribe audio files into text format accurately and efficiently.
Song Transcriptor App Using Python
Below is the implementation of the Song Transcriptor App Using Python:
Create a Virtual Environment
First, create the virtual environment using the below commands
python -m venv env
.\env\Scripts\activate.ps1
Install Necessary Library
First, it is essential to install the Whisper library and Streamlit. Streamlit is employed for creating the GUI, while Whisper is utilized for audio whispering. To install these libraries, execute the following commands.
pip install whisper
pip install streamlit
File Structure

Writing Python Code (app.py)
Below, are the step-by-step explanation of the code:
Step 1 :Imports and Library Initialization
Below, code imports the necessary libraries. Streamlit is used for creating web applications with simple Python scripts. The 'os' module provides a way to interact with the operating system, and 'whisper' is presumably a library for handling audio-related tasks.
Python3
import streamlit as st
import os
import whisper
Step 2: Function to Save Uploaded File
below, code function takes an uploaded file and a path as input and saves the file to the specified path. It uses the 'os.path.join' method to create the full file path and writes the file using the 'write' method.
Python3
def save_uploaded_file(uploaded_file, save_path):
with open(os.path.join(save_path, uploaded_file.name), "wb") as f:
f.write(uploaded_file.getbuffer())
Step 3: Loading Whisper Model
Below, code function initializes and loads a whisper model named "base" and assigns it to the variable 'model'. The loaded model is then used globally in the script.
Python3
def load_whisper_model():
model = whisper.load_model("base")
return model
model = load_whisper_model()
Step 4: Audio Transcription Function
below, code function transcribes an audio file located at 'mp3_filepath' using the loaded whisper model. It returns the transcribed text from the audio.
Python3
def transcribe_audio(mp3_filepath):
# Transcribe using whisper
result = model.transcribe(mp3_filepath)
transcription = result['text']
return transcription
Step 5: Main Streamlit Application
This is the main part of the code where the Streamlit application is created. It provides a simple web interface for users to upload an MP3 audio file, displays the uploaded file, saves it, transcribes the audio using the Whisper model, and then displays the transcribed text in a Streamlit text area. The application is executed if the script is run directly.
Python3
def main():
st.title("Song Transcriber")
# File uploader widget
uploaded_file = st.file_uploader("Upload an audio file", type="mp3")
if uploaded_file is not None:
save_path = "audio_files" # Folder to save the uploaded file
os.makedirs(save_path, exist_ok=True)
# Display the uploaded file
st.audio(uploaded_file, format='audio/mp3')
# Save the uploaded file
save_uploaded_file(uploaded_file, save_path)
st.success("Audio file uploaded successfully.")
# Transcribe the audio
transcribed_text = transcribe_audio(
f"audio_files/{uploaded_file.name}")
# Display the transcribed text
st.subheader("Transcribed Text:")
st.text_area("Transcribed Text", value=transcribed_text, height=200)
if __name__ == "__main__":
main()
Complete Code Implementation
Here is the complete code implementation that we have used in app.py file.
app.py
Python3
import streamlit as st
import os
import whisper
def save_uploaded_file(uploaded_file, save_path):
with open(os.path.join(save_path, uploaded_file.name), "wb") as f:
f.write(uploaded_file.getbuffer())
def load_whisper_model():
model = whisper.load_model("base")
return model
model = load_whisper_model()
def transcribe_audio(mp3_filepath):
# Transcribe using whisper
result = model.transcribe(mp3_filepath)
transcription = result['text']
return transcription
def main():
st.title("Song Transcriber")
# File uploader widget
uploaded_file = st.file_uploader("Upload an audio file", type="mp3")
if uploaded_file is not None:
save_path = "audio_files" # Folder to save the uploaded file
os.makedirs(save_path, exist_ok=True)
# Display the uploaded file
st.audio(uploaded_file, format='audio/mp3')
# Save the uploaded file
save_uploaded_file(uploaded_file, save_path)
st.success("Audio file uploaded successfully.")
# Transcribe the audio
transcribed_text = transcribe_audio(
f"audio_files/{uploaded_file.name}")
st.subheader("Transcribed Text:")
st.text_area("Transcribed Text", value=transcribed_text, height=200)
if __name__ == "__main__":
main()
Run the Server
For run the server use the below command
streamlit run script_name.py
Upload any audio file and this app will transcript it into text and return the output in text form
Output
Song Transcriptor App Using Python
Similar Reads
Build a Voice Recorder GUI using Python
Prerequisites: Python GUI â tkinter, Create a Voice Recorder using Python Python provides various tools and can be used for various purposes. One such purpose is recording voice. It can be done using the sounddevice module. This recorded file can be saved using the soundfile module Module NeededSoun
2 min read
Real-Time Translation App Using Python
In this article, we'll delve into the creation of a potent real-time translation application using Python. Leveraging the capabilities of the Google Translate API, we'll walk you through building an intuitive graphical user interface (GUI) with the Tkinter library. With just a few lines of code, you
5 min read
Build a Video Transcription
In the modern days of content creation, video content is very often. From educational tutorials to entertainment everywhere videos serve as a powerful medium for conveying information. However, the accessibility and searchability of video content are often hindered by the lack of textual representat
6 min read
Language Translator Using Google API in Python
API stands for Application Programming Interface. It acts as an intermediate between two applications or software. In simple terms, API acts as a messenger that takes your request to destinations and then brings back its response for you. Google API is developed by Google to allow communications wit
3 min read
Python - Morse Code Translator GUI using Tkinter
Prerequisites : Introduction to tkinter | Morse Code Translator Python offers multiple options for developing a GUI (Graphical User Interface). Out of all the GUI methods, Tkinter is the most commonly used method. Python with Tkinter outputs the fastest and easiest way to create GUI applications. In
6 min read
How to build a Random Story Generator using Python?
In this section, we are going to make a very interesting beginner-level project of Python. It is a random story generator. The random story generator project aims to generate random stories every time user executes the code. A story is made up of a collection of sentences. We will choose random phra
4 min read
Build a Virtual Assistant Using Python
Virtual desktop assistant is an awesome thing. If you want your machine to run on your command like Jarvis did for Tony. Yes it is possible. It is possible using Python. Python offers a good major library so that we can use it for making a virtual assistant. Windows has Sapi5 and Linux has Espeak wh
8 min read
Create a GUI to extract Lyrics from song Using Python
In this article, we are going to write a python script to extract lyrics from the song and bind with its GUI application. We will use lyrics-extractor to get lyrics of a song just by passing in the song name, it extracts and returns the song's title and song lyrics from various websites. Before star
3 min read
Story Generator App Using Python
In the realm of programming and natural language processing, there's an opportunity to create engaging and creative applications that spark the imagination. One such project is the development of a Story Generator App using Python. In this article, we'll embark on a journey to understand how to buil
4 min read
Create API Tester using Python Requests Module
Prerequisites: Python Requests module, API In this article, we will discuss the work process of the Python Requests module by creating an API tester. API stands for Application Programming Interface (main participant of all the interactivity). It is like a messenger that takes our requests to a syst
3 min read