Empowering Your Business
  • Lost password
  • Orders
  • Account details
Tuesday, June 17, 2025
  • Login
  • Register
  • Home
  • Entrepreneurs
  • News & Politics
  • Events
  • Tech & Ai
  • Real Estate
  • Insights
  • Mindset
  • Home
  • Entrepreneurs
  • News & Politics
  • Events
  • Tech & Ai
  • Real Estate
  • Insights
  • Mindset
No Result
View All Result
Empowering Your Business

One-Click Audio Transcription Script: Seamless Setup and Processing

November 19, 2024
in AI and Machine Learning, Tech & Ai
Reading Time: 10 mins read
0
Home Tech & Ai AI and Machine Learning

This updated one-click script simplifies audio transcription like never before. It checks for and installs Homebrew, Python, and FFmpeg automatically, ensures the necessary Python packages are installed, and processes MP4 or MP3 files into text effortlessly. With minimal setup and a user-friendly approach, this script converts your audio into transcripts with a single command. Save time, eliminate setup hassles, and streamline your transcription workflow today!

Improvements and Fixes:

1. Version Comparison for Python:

The comparison of Python versions using if [[ “$PYTHON_VERSION” < “3.9” ]] may not work as intended because version strings aren’t directly comparable. Use sort -V for proper version comparison:

if [[ $(echo -e “$PYTHON_VERSION\n3.9” | sort -V | head -n1) != “3.9” ]]; then

2. Python Package Installation:

Use python3 -m pip instead of pip3 for consistency, especially since pip may not always be installed globally:

python3 -m pip install –upgrade pip

python3 -m pip install ffmpeg-python git+https://github.com/openai/whisper.git torch torchvision torchaudio –index-url https://download.pytorch.org/whl/cpu

3. Error Handling:

Add error handling for critical commands (e.g., Homebrew, Python, FFmpeg installation). Use || exit 1 to terminate the script if a step fails.

4. Script Portability:

The script is Mac-specific due to Homebrew. If portability is a concern (e.g., Linux users), you can check for package managers like apt or yum.

5. Processing Files:

If the $VOICE_DIR contains non-audio files, the loop will still attempt to process them. Add a check for supported file extensions:

if [[ “$EXT” =~ ^(mp4|mp3|wav)$ ]]; then

6. Temporary WAV Files:

Ensure temporary WAV files created during MP4 conversion are cleaned up to avoid clutter:

trap ‘rm -f “$VOICE_DIR/$BASENAME.wav”‘ EXIT

7. Dependencies Check Before Processing:

Ensure all dependencies are installed successfully before processing files. This avoids starting the transcription process if something is missing.

8. Improve Logging:

Use clearer messages and a log file to debug issues if needed:

LOG_FILE=”$HOME/transcriber.log”

echo “Starting script…” | tee -a “$LOG_FILE”

Updated Script:

#!/bin/bash

# Define folders

VOICE_DIR=”$HOME/voice”

TRANSCRIPT_DIR=”$HOME/transcript”

# Create folders if they don’t exist

mkdir -p “$VOICE_DIR” “$TRANSCRIPT_DIR”

# Log file

LOG_FILE=”$HOME/transcriber.log”

echo “Starting script at $(date)” | tee -a “$LOG_FILE”

# Function to check and install Homebrew

check_homebrew() {

    if ! command -v brew &> /dev/null; then

        echo “Homebrew not found. Installing Homebrew…” | tee -a “$LOG_FILE”

        /bin/bash -c “$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)” || { echo “Homebrew installation failed!” | tee -a “$LOG_FILE”; exit 1; }

        echo “Homebrew installed successfully.” | tee -a “$LOG_FILE”

    else

        echo “Homebrew is already installed.” | tee -a “$LOG_FILE”

    fi

}

# Function to check Python installation

check_python() {

    if ! command -v python3 &> /dev/null; then

        echo “Python3 not found. Installing…” | tee -a “$LOG_FILE”

        brew install python || { echo “Python installation failed!” | tee -a “$LOG_FILE”; exit 1; }

    fi

    echo “Python3 found. Checking version…” | tee -a “$LOG_FILE”

    PYTHON_VERSION=$(python3 –version | awk ‘{print $2}’)

    if [[ $(echo -e “$PYTHON_VERSION\n3.9” | sort -V | head -n1) != “3.9” ]]; then

        echo “Python version is below 3.9. Updating…” | tee -a “$LOG_FILE”

        brew upgrade python || { echo “Python upgrade failed!” | tee -a “$LOG_FILE”; exit 1; }

    else

        echo “Python version is sufficient.” | tee -a “$LOG_FILE”

    fi

}

# Function to install required Python packages

install_dependencies() {

    echo “Installing required Python packages…” | tee -a “$LOG_FILE”

    python3 -m pip install –upgrade pip || { echo “Pip upgrade failed!” | tee -a “$LOG_FILE”; exit 1; }

    python3 -m pip install ffmpeg-python git+https://github.com/openai/whisper.git torch torchvision torchaudio –index-url https://download.pytorch.org/whl/cpu || { echo “Package installation failed!” | tee -a “$LOG_FILE”; exit 1; }

}

# Function to check FFmpeg installation

check_ffmpeg() {

    if ! command -v ffmpeg &> /dev/null; then

        echo “FFmpeg not found. Installing…” | tee -a “$LOG_FILE”

        brew install ffmpeg || { echo “FFmpeg installation failed!” | tee -a “$LOG_FILE”; exit 1; }

    else

        echo “FFmpeg is already installed.” | tee -a “$LOG_FILE”

    fi

}

# Check and install dependencies

echo “Checking dependencies…” | tee -a “$LOG_FILE”

check_homebrew

check_python

check_ffmpeg

install_dependencies

# Prompt user to place file in voice folder

echo “Place your MP4 or MP3 files in the folder: $VOICE_DIR” | tee -a “$LOG_FILE”

echo “Press Enter when you’re ready to proceed…” | tee -a “$LOG_FILE”

read

# Process files in voice folder

echo “Processing files…” | tee -a “$LOG_FILE”

for file in “$VOICE_DIR”/*; do

    if [[ -f “$file” ]]; then

        FILENAME=$(basename “$file”)

        BASENAME=”${FILENAME%.*}”

        EXT=”${FILENAME##*.}”

        if [[ “$EXT” =~ ^(mp4|mp3|wav)$ ]]; then

            # Convert MP4 to WAV if needed

            if [[ “$EXT” == “mp4” ]]; then

                echo “Converting $FILENAME to WAV…” | tee -a “$LOG_FILE”

                ffmpeg -i “$file” -ar 16000 -ac 1 -c:a pcm_s16le “$VOICE_DIR/$BASENAME.wav” || { echo “Conversion failed!” | tee -a “$LOG_FILE”; exit 1; }

                file=”$VOICE_DIR/$BASENAME.wav”

            fi

            # Run transcription using Whisper

            echo “Transcribing $FILENAME…” | tee -a “$LOG_FILE”

            python3 -m whisper “$file” –language fa –model small –output_dir “$TRANSCRIPT_DIR” || { echo “Transcription failed!” | tee -a “$LOG_FILE”; exit 1; }

            echo “Transcription completed for $FILENAME. Check the transcript folder: $TRANSCRIPT_DIR” | tee -a “$LOG_FILE”

        else

            echo “Skipping unsupported file: $FILENAME” | tee -a “$LOG_FILE”

        fi

    fi

done

echo “All tasks completed!” | tee -a “$LOG_FILE”

Key Enhancements:

1. Improved Python version comparison.

2. Error handling for critical steps.

3. Temporary file cleanup.

4. Support for only valid file types.

5. Logging for troubleshooting.

Let me know if you’d like further adjustments!

Share this:

  • Share
  • Click to share on X (Opens in new window) X
  • Click to share on Facebook (Opens in new window) Facebook
  • Click to email a link to a friend (Opens in new window) Email
  • Click to share on Reddit (Opens in new window) Reddit
  • Click to share on Tumblr (Opens in new window) Tumblr
  • Click to share on Pinterest (Opens in new window) Pinterest
  • Click to share on WhatsApp (Opens in new window) WhatsApp
  • Click to share on Mastodon (Opens in new window) Mastodon
Tags: AI transcription toolsaudio transcriptionautomated workflowbash automationbash scriptingFFmpeg installationHomebrew installationHomebrew scriptinstall FFmpegMP3 to textMP3 transcriptionMP4 conversionMP4 to WAVone-click scriptPython 3.9 upgradePython dependenciesscript efficiencytech productivityterminal automationtranscription setupWhisper transcription
ShareTweetPin
Previous Post

Travel Trends for 2025: The Most Anticipated Destinations

Next Post

Exploring the Future of Paradise

Jason Imarka

Next Post
Exploring the Future of Paradise

Exploring the Future of Paradise

  • Trending
  • Comments
  • Latest
The Connection Between Blue Light, Operation Paperclip, and Behavior Control

The Connection Between Blue Light, Operation Paperclip, and Behavior Control

November 21, 2024

Allodial Ownership: The Ultimate Untouchable Asset

December 22, 2024
Your Court Case in the Hands of AI: How Grok 3 is Revolutionizing Justice

Your Court Case in the Hands of AI: How Grok 3 is Revolutionizing Justice

November 30, 2024
How Costco Gold Bar Flipping Works: A Clever Arbitrage Strategy

How Costco Gold Bar Flipping Works: A Clever Arbitrage Strategy

November 17, 2024
VERCINI at Fashion Show Las Vegas

Fashion Show Mall

2
VERCINI at Galleria at Sunset

Galleria at Sunset

1
VERCINI at Town Square Las Vegas

Town Square Las Vegas

1

The Brainiac of Discovery

0

Miss Thailand Opal Suchata Crowned Miss World 2025 In Hyderabad

May 31, 2025

Explained: Trump’s Multi-Pronged Attack On Harvard University

May 30, 2025

Diego Maradona’s Death Trial Declared Null After 2 Months, 40 Witnesses

May 29, 2025

Trump’s Team Cite “Fragile” India-Pak Ceasefire To Justify Tariffs In Court

May 28, 2025

Recent News

Miss Thailand Opal Suchata Crowned Miss World 2025 In Hyderabad

May 31, 2025
19

Explained: Trump’s Multi-Pronged Attack On Harvard University

May 30, 2025
13

Diego Maradona’s Death Trial Declared Null After 2 Months, 40 Witnesses

May 29, 2025
15

Trump’s Team Cite “Fragile” India-Pak Ceasefire To Justify Tariffs In Court

May 28, 2025
13

Business

  • Business Center
  • Blog & Updates
  • Marketing
  • Conventions
  • Marketplace

Entrepreneurs

  • Start a Business
  • Advertising
  • Digital Media
  • Packages
  • Consultation

Influencers

  • Find Sponsors
  • Hire Freelancers
  • Omnichannel
  • Get Promoted
  • Merchandise

Industries

  • Dispensaries
  • Shopping Malls
  • Fashion
  • Contractors
  • Real Estate

Get Started

  • Register Your Business
  • Become a Vendor
  • Pro Tools

Marketplace

  • Vendors List
  • Printing Products
  • Sign Products
  • Exhibit Displays

Local Directory

  • East Coast
  • West Coast
  • Carribean Islands
  • Hawaiian Islands

Experts

  • Web Experts
  • Photographers
  • Content Creators
  • Designers

Real Estate Pros

  • Realtors
  • Contractors
  • Remodeler
  • Suppliers
Empowering Your Business
Alsett.com, your ultimate destination for business insights, fashion trends, and lifestyle inspiration.
Facebook-f Instagram Youtube X-twitter
Copyright © 2024 Alsett.com, All rights reserved.
  • Term of use
  • Privacy Policy

Welcome Back!

Login to your account below

Forgotten Password? Sign Up

Create New Account!

Fill the forms below to register

All fields are required. Log In

Retrieve your password

Please enter your username or email address to reset your password.

Log In
No Result
View All Result
  • Home
  • Business Center
  • Influencers Hub
  • Brands
  • Blog
  • News
    • Insights
    • Entrepreneurs
    • Mindset
    • Events & Trade Shows
    • Tech & Ai
    • Real Estate & Housing
    • News & Politics
    • Esoteric & Beyond

© 2024