-
-
Notifications
You must be signed in to change notification settings - Fork 504
Add audio transcription script using Faster Whisper #533
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Syed-56
wants to merge
3
commits into
wasmerio:main
Choose a base branch
from
Syed-56:transcribing
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,74 @@ | ||
| # MUST READ BEFORE EXECUTION (ONE TIME ONLY) | ||
|
|
||
| This script allows you to **transcribe audio files (MP3, WAV, etc.) to text** using the **Faster Whisper** Python library. Please read these instructions carefully before running the script. | ||
|
|
||
| --- | ||
|
|
||
| ## 1️⃣ Prerequisites | ||
|
|
||
| 1. **Install Python (3.8 or higher)** | ||
| Download and install from [https://www.python.org/downloads/](https://www.python.org/downloads/). | ||
| Make sure to **add Python to your system PATH** during installation. | ||
| OR you can simply run this command in terminal to install python: "winget install Python.Python.3" | ||
| for MAC: brew install python | ||
|
|
||
| 2. **Install ffmpeg** (required for audio decoding) | ||
| - **Windows:** [https://ffmpeg.org/download.html](https://ffmpeg.org/download.html) | ||
| - **Linux:** `sudo apt install ffmpeg` | ||
| - **Mac:** `brew install ffmpeg` | ||
| Make sure ffmpeg is **added to your system PATH** so the script can find it. (Explanation in End on how to do this) | ||
| Now you can verify if both are installed by writing "python --version" or "py --version" and "ffmpeg -version" | ||
| --- | ||
|
|
||
| ## 2️⃣ Audio File Requirements | ||
|
|
||
| - Place the audio file you want to transcribe **in the same folder** as the script. | ||
| - Make sure to use the **correct file extension** (e.g., `.mp3`, `.wav`). | ||
| - Also works for videos (.mp4) | ||
| - The output transcription will also be saved in the same folder with the filename: | ||
|
|
||
|
|
||
| --- | ||
|
|
||
| ## 3️⃣ Choosing the Model | ||
|
|
||
| The script supports the following **Faster Whisper models**. Please choose the one that fits your needs: | ||
|
|
||
| | Model | Speed & Size | Accuracy | | ||
| |---------|------------------------------|-------------------------------| | ||
| | tiny | Fastest, smallest | Least accurate | | ||
| | small | Fast, small | Slightly more accurate | | ||
| | base | Moderate speed & size | Good accuracy | | ||
| | medium | Slower, larger | More accurate | | ||
| | large | Slowest, largest | Most accurate | | ||
|
|
||
| **Tip:** Use `base` for a good balance between speed and accuracy. Model names are **case-insensitive**. | ||
|
|
||
| --- | ||
|
|
||
| ## 4️⃣ Running the Script | ||
|
|
||
| 1. Open a terminal or command prompt in the folder containing the script. | ||
| 2. Run the script: type "python transcription.py" | ||
| 3. Follow Along the input instructions prompted on screen | ||
|
|
||
| ## 5 Setting ffmpeg in Your System PATH | ||
|
|
||
| To make ffmpeg accessible to the script: | ||
|
|
||
| **Windows:** | ||
| 1. Download and unzip ffmpeg. | ||
| 2. Copy the path to the `bin` folder (e.g., `C:\ffmpeg\bin`). | ||
| 3. Open **Environment Variables → Path → Edit → New**, paste the path, and click **OK**. | ||
| 4. Restart the terminal or command prompt. | ||
|
|
||
| **Linux / Mac:** | ||
| write export PATH=$PATH:/path/to/ffmpeg/bin | ||
|
|
||
| ## Developer | ||
| - GitHub: https://github.com/Syed-56 | ||
| - LinkedIn: https://www.linkedin.com/in/syedsultan10 | ||
|
|
||
| ## Dependencies & Licenses | ||
| - Faster Whisper: MIT License (https://github.com/guillaumekln/faster-whisper) | ||
| - ffmpeg: LGPL/GPL License (https://ffmpeg.org) |
This file contains hidden or 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 @@ | ||
| import sys | ||
| import subprocess | ||
| import shutil | ||
|
|
||
| #functions to isntall python packages | ||
| def installPackage(pkgName): | ||
| print(f"[INFO] {pkgName} not found. Installing...") | ||
| subprocess.check_call([sys.executable, "-m", "pip", "install", pkgName]) | ||
| print(f"[INFO] {pkgName} installed successfully!") | ||
|
|
||
| try: | ||
| from faster_whisper import WhisperModel | ||
| except ImportError: | ||
| installPackage("faster_whisper") | ||
| from faster_whisper import WhisperModel | ||
|
|
||
| # Check for ffmpeg | ||
| if shutil.which("ffmpeg") is None: | ||
| print( | ||
| "[ERROR] ffmpeg not found on your system.\n" | ||
| "Please install ffmpeg to use this script:\n" | ||
| "- Windows: https://ffmpeg.org/download.html\n" | ||
| "- Linux: sudo apt install ffmpeg\n" | ||
| "- Mac: brew install ffmpeg" | ||
| ) | ||
| sys.exit(1) | ||
|
|
||
| print("[INFO] All dependencies are ready!") | ||
|
|
||
| audio_file = input("Enter the path to your audio file (MP3, WAV, MP4 etc.): ").strip() | ||
| valid_models = ["tiny", "small", "base", "medium", "large"] | ||
| print("Models (Sorted from Fastest-Smallest-Least Accurate To Slowest-Largest-Most Accurate):-\n") | ||
| print("Make Sure to write .en after writing model name if you only want english transcription (Less work for model)\n") | ||
| print(valid_models) | ||
| model_size = input("\nEnter the model size: ").strip().lower() | ||
|
|
||
| if model_size not in valid_models: | ||
| print(f"[ERROR] Invalid model size '{model_size}'. Please choose from {valid_models}.") | ||
| sys.exit(1) | ||
|
|
||
| model = WhisperModel(model_size) | ||
|
|
||
| import os | ||
| if not os.path.isfile(audio_file): | ||
| print(f"[ERROR] File '{audio_file}' does not exist. Please check the path and try again.") | ||
| sys.exit(1) | ||
|
|
||
| output_file = audio_file.rsplit(".", 1)[0] + "_transcript.txt" | ||
| segments, info = model.transcribe(audio_file) | ||
|
|
||
| with open(output_file, "w", encoding="utf-8") as f: | ||
| for segment in segments: | ||
| f.write(segment.text + "\n") | ||
| print(f"[INFO] Transcription saved to {output_file}") | ||
| print("\n -- Scripted by Syed Sultan (github = Syed-56)") | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.