<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Ammar Alghamdi on Medium]]></title>
        <description><![CDATA[Stories by Ammar Alghamdi on Medium]]></description>
        <link>https://medium.com/@ammarsxx?source=rss-6b78db0e3a3------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*AAsTVkGSbLiORP50u06dEw.gif</url>
            <title>Stories by Ammar Alghamdi on Medium</title>
            <link>https://medium.com/@ammarsxx?source=rss-6b78db0e3a3------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 18 Nov 2026 02:10:08 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ammarsxx/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Speech Recognition with Apple’s MLX and OpenAI’s Whisper for Transcription]]></title>
            <link>https://medium.com/@ammarsxx/speech-recognition-with-apples-mlx-and-openai-s-whisper-for-transcription-b3f27cbfcfcb?source=rss-6b78db0e3a3------2</link>
            <guid isPermaLink="false">https://medium.com/p/b3f27cbfcfcb</guid>
            <category><![CDATA[open-source]]></category>
            <category><![CDATA[speech-recognition]]></category>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[Ammar Alghamdi]]></dc:creator>
            <pubDate>Tue, 17 Sep 2024 17:37:34 GMT</pubDate>
            <atom:updated>2024-09-17T17:48:27.389Z</atom:updated>
            <content:encoded><![CDATA[<p>In this guide, we’ll explore how to leverage OpenAI’s Whisper models — speech recognition models — to help transcribe an audio using Apple’s Core ML framework (MLX). This guide is created to help individuals use ML locally without paying a dime!</p><h3>1. Prerequisites</h3><p><strong>Knowledge Requirements:</strong></p><ul><li>Basic familiarity with using the <a href="https://support.apple.com/guide/terminal/welcome/mac"><strong>Terminal</strong></a> on macOS.</li><li>Understanding of installing software packages via the command line.</li></ul><p><strong>Software Requirements:</strong></p><ul><li><strong>macOS Monterey (12.3)</strong> or later (required for MPS support).</li><li><a href="https://brew.sh/"><strong>Homebrew</strong></a> (package manager for macOS).</li><li><strong>Python 3.9</strong> or later.</li><li><a href="https://pytorch.org/"><strong>PyTorch</strong></a> with MPS (Metal Performance Shaders) support.</li><li><a href="https://openai.com/index/whisper/"><strong>OpenAI Whisper</strong></a> package.</li></ul><h3>2. Setting Up the Environment</h3><p>Let’s begin by setting up the necessary environment to run Whisper on your Mac.</p><p><strong>Install Homebrew</strong></p><p>Homebrew is a package manager for macOS that simplifies the installation of software.</p><p><strong>Check if Homebrew is installed:</strong></p><pre>brew - version</pre><p>If it returns a version number, you can skip this step. If not, install Homebrew:</p><p><strong>Install Homebrew:</strong></p><pre>/bin/bash -c &quot;$(curl -fsSL &lt;https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh&gt;)&quot;</pre><p><strong>Install Python 3</strong></p><p>macOS comes with Python 2.x by default. We’ll need Python 3.9 or later.</p><p><strong>Check if Python 3 is installed:</strong></p><pre>python3 --version</pre><p>If Python 3.9 or later is installed, proceed to the next step. If not:</p><p><strong>Install Python 3:</strong></p><pre>brew install python@3.11</pre><p>Verify the installation:</p><pre>python3 --version</pre><h3>3. Install PyTorch with MPS Support</h3><p>PyTorch is the machine learning library required to run Whisper. The M2 chip uses Apple Silicon, so we’ll install PyTorch with <strong>MPS (Metal Performance Shaders)</strong> support to utilize the GPU capabilities.</p><p><strong>Create a Python Virtual Environment (Optional but Recommended):</strong></p><p>It’s a good practice to use a virtual environment to manage your Python packages.</p><pre>python3 -m venv whisper_env<br>source whisper_env/bin/activate</pre><p>Your prompt should now indicate that you’re in the <em>whisper_env </em>environment.</p><p><strong>Install PyTorch</strong></p><p>PyTorch has added support for MPS in version 1.12 and later. Since you’re using macOS, you can install PyTorch via pip with MPS support.</p><p><strong>Install PyTorch nightly build (Recommended for MPS support):</strong></p><pre>pip install --pre torch torchvision torchaudio --index-url &lt;https://download.pytorch.org/whl/nightly/cpu&gt;</pre><blockquote>Note: The above command installs the latest nightly build with CPU support. For MPS support, use:</blockquote><pre>pip install torch torchvision torchaudio</pre><p>However, for MPS (GPU) support, make sure your macOS version is 12.3 or later, and you have Python 3.10 or later.</p><p>Verify the installation:</p><pre>python -c &quot;import torch; print(torch.__version__)&quot;</pre><p><strong>Test MPS Support</strong></p><p>Check if PyTorch can detect the MPS device:</p><pre>python -c &quot;import torch; print(torch.backends.mps.is_available())&quot;</pre><p>If it returns <em>True</em>, MPS is available.</p><p><strong>Install Whisper</strong></p><p>Now, install the Whisper package:</p><pre>pip install git+https://github.com/openai/whisper.git</pre><p>Alternatively, you can install via pip directly:</p><pre>pip install -U openai-whisper</pre><p><strong>Note:</strong> The -U flag ensures you&#39;re installing the latest version.</p><p>Verify the installation:</p><pre>whisper --help</pre><p>You should see the help message for the Whisper CLI tool.</p><h3>4. Transcribing Audio with Whisper</h3><p><strong>Using the Whisper CLI:</strong></p><p>Whisper provides a command-line interface (CLI) for transcribing audio files.</p><p><strong>Transcribing Your Voice/Audio file:</strong></p><p><strong>Step 1: Place Your Audio File</strong></p><p>Ensure your voice note/audio is in a supported audio format (e.g., WAV, MP3, M4A). For best results, use a high-quality audio file.</p><p>Let’s assume your audio file is named voice_note.m4a and is located in your Documents folder.</p><p><strong>Step 2: Open Terminal and Navigate to the Directory</strong></p><pre>cd ~/Documents</pre><p><strong>Step 3: Choose the Appropriate Whisper Model</strong></p><p>Whisper offers several models of different sizes:</p><ul><li>tiny</li><li>base</li><li>small</li><li>medium</li><li>large</li></ul><p>Larger models are more accurate but require more computational resources. Using the base or small model is recommended for a balance between speed and accuracy.</p><p><strong>Step 4: Transcribe the Audio File</strong></p><p>Transcribe using the small model:</p><pre>whisper voice_note.m4a --model small --device mps</pre><p><strong>Explanation:</strong></p><ul><li>voice_note.m4a: The path to your audio file.</li><li>-model small: Specifies the model size.</li><li>-device mps: Tells PyTorch to use the MPS backend (GPU acceleration on Apple Silicon).</li></ul><p><strong>Step 5: Wait for the Transcription to Complete</strong></p><p>Depending on the model size and length of the audio, transcription may take some time. The small model should transcribe a 1-hour audio file relatively efficiently on an M2 chip.</p><p><strong>Step 6: Access the Transcribed Text</strong></p><p>By default, Whisper saves the transcription in the same directory as your audio file, with the following files:</p><ul><li>voice_note.txt: The full transcription.</li><li>voice_note.srt: SubRip subtitle file.</li><li>voice_note.vtt: WebVTT subtitle file.</li><li>voice_note.csv: CSV file with timestamps and text.</li></ul><p>You can open voice_note.txt to view the transcription.</p><h3>5. Optimizing Performance on M2</h3><p>To make the most out of your MacBook Air M2, consider the following optimizations.</p><p><strong>Understanding Model Sizes</strong></p><p>Whisper models vary in size and performance:</p><figure><img alt="Whisper models vary in size and performance" src="https://cdn-images-1.medium.com/max/835/1*vIiBW_UPpQDO0F6qEUVPmA.png" /></figure><ul><li><strong>Parameters</strong>: Number of parameters in the model.</li><li><strong>Disk Space</strong>: Approximate size of the model on disk.</li><li><strong>Relative Speed</strong>: Speed relative to the large model (higher is faster).</li><li><strong>Recommended RAM</strong>: Minimum RAM for optimal performance.</li></ul><h3>6. Additional Performance Tips</h3><ul><li><strong>Close Unnecessary Applications</strong>: Free up RAM by closing other applications during transcription.</li><li><strong>Use FP16 Precision</strong>: By default, Whisper uses FP16 precision which reduces memory usage and speeds up computation. This is enabled by default on GPUs.</li></ul><p><strong>Forcing CPU Usage (If Needed)</strong></p><p>If you encounter issues with MPS, you can force Whisper to use the CPU:</p><pre>whisper voice_note.m4a --model small --device cpu</pre><blockquote>Note: This will be significantly slower than using MPS.</blockquote><h3>Additional Resources</h3><ul><li><a href="https://github.com/openai/whisper/issues">OpenAI Whisper GitHub Issues</a>: Check for any reported issues similar to yours.</li><li><a href="https://pytorch.org/docs/stable/notes/mps.html">PyTorch MPS Backend Documentation</a>: Learn about the current limitations of the MPS backend.</li><li><a href="https://github.com/openai/whisper/discussions">Whisper Discussion Forums</a>: Engage with the community for support and updates.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b3f27cbfcfcb" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>