DEV Community

Artur Piszek
Artur Piszek

Posted on • Originally published at piszek.com on

Transcribing your iOS Voice Memos to Markdown with Whisper

Open AI has recently introduced an Open-Source library to transcribe voice recordings, and it immediatelly caught my eye. I like automating things, and transcribing memos is a great example of a high leverage automation.

  1. Recording voice or video is much faster and easier than writing text
  2. Text is much easier to parse and consume than video or audio.

When I record a voice memo for myself and a bot transcribes it, I have something easy to produce, but also searchable and easily read.

As my current note-taking app is Logseq, it auto-imports those markdown files to my notes database.

Image description

Installing Whisper

If you have Python, pip3 and ffmpeg ready, you should be able to run a command like:

pip3 install git+https://github.com/openai/whisper.git
Enter fullscreen mode Exit fullscreen mode

Then you can run it on any audio or video file:

whisper /path/to/file
Enter fullscreen mode Exit fullscreen mode

More instruction in the GH repo.

iOS Voice Memos

When iCloud sync is enabled, the voice memos from your phone sync to your laptop via icloud. This will be perfect!

The recordings are stored in a directory like this: (replace artpi with your username)

/Users/artpi/Library/Application Support/com.apple.voicememos/Recordings/
Enter fullscreen mode Exit fullscreen mode

Unusually accessible for an Apple product, but a win for us! Let’s put it all together. The following code will:

  1. Read all .m4a files from /Users/artpi/Library/Application Support/com.apple.voicememos/Recordings/
  2. Transcribe
  3. Save each as /Users/artpi/GIT/logseq/pages/RECORDING_NAME.md file
  4. When re-run, it will skip the files already saved.

<?php
//https://piszek.com/?p=5874

function sync_apple_voice_memos( $dir, $save_dir, $whisper_dir ) {
    foreach ( glob( dir ) as $filename ) {
        $name = basename( $filename, ".m4a" );
        $file_to_save = $save_dir . '/Voice Memo - ' . $name . '.md' ;
        // Only proceed if file not already transcribed
        if ( ! file_exists( $file_to_save ) ) {
            $lines = [];
            exec( "{$whisper_dir} \"{$filename}\"", $lines );

            $lines = array_slice( $lines, 2 ); // Some default headers.
            $lines = array_map( function( $line ){
                return preg_replace( '#\[[0-9.:]+ --> [0-9.:]+\]\s+(.*?)$#is', '- \\1', $line );
            }, $lines );

            if ( $lines ) {
                file_put_contents( $file_to_save, implode( "\n", $lines ) );
            }
        }
    }
}

sync_apple_voice_memos(
    '/Users/artpi/Library/Application Support/com.apple.voicememos/Recordings/*.m4a',
    '/Users/artpi/GIT/logseq/pages',
    '/opt/homebrew/bin/whisper'
);
Enter fullscreen mode Exit fullscreen mode

More Logseq imports

Here are some other importer ideas for Logseq:

I wrote a bunch of scripts to import everything to my @logseq, and it is glorious.

I have an overview of every day, including today.

It prevents me from opening a bunch of apps to check notifications and puts me in a more proactive frame of mind.

Here is what syncs hourly:

— Minimum Viable Polish (@artpi) August 2, 2022

The post Transcribing your iOS Voice Memos to Markdown with Whisper appeared first on Artur Piszek.

Top comments (1)

Collapse
 
vojto profile image
Vojtech Rinik

Oh, that's a great approach! I was thinking about the same problem, and ended up biulding a whole app - Whisper Memos.