Skip to content

Instantly share code, notes, and snippets.

@Thomascountz
Last active June 10, 2025 23:25
Show Gist options
  • Save Thomascountz/287d7dd1e04674d22a6396433937cd29 to your computer and use it in GitHub Desktop.
Save Thomascountz/287d7dd1e04674d22a6396433937cd29 to your computer and use it in GitHub Desktop.
Extract transcript text from Apple Memos M4A file
#!/bin/bash
if ! command -v mp4extract >/dev/null 2>&1; then
echo "Error: mp4extract is not installed or not in your PATH." >&2
echo "Please install it and try again" >&2
exit 1
fi
if ! command -v jq >/dev/null 2>&1; then
echo "Error: jq is not installed or not in your PATH." >&2
echo "Please install it and try again." >&2
exit 1
fi
if [ -z "$1" ]; then
echo "Usage: $0 <input_file>"
exit 1
fi
temp_file=$(mktemp)
trap 'rm -f "$temp_file"' EXIT
mp4extract --payload-only moov/trak/udta/tsrp "$1" "$temp_file"
if [ ! -s "$temp_file" ]; then
echo "Warning: mp4extract produced an empty file. No transcript data found or error in extraction path (moov/trak/udta/tsrp)." >&2
exit 1
fi
cat "$temp_file" | jq '.attributedString.runs | map(if type == "string" then . else empty end) | join("")'
# MIT License
# Copyright (c) 2025 Thomas Countz
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment