Skip to content

Instantly share code, notes, and snippets.

@bmedicke
Last active March 9, 2024 09:01
Show Gist options
  • Save bmedicke/6dc692723212757df27c819d137ccc0b to your computer and use it in GitHub Desktop.
Save bmedicke/6dc692723212757df27c819d137ccc0b to your computer and use it in GitHub Desktop.
extract ChatGTP aac audio from Chrome's .har files
#!/bin/bash
# Check if there are any .har files in the current directory
har_files=$(echo *.har)
if [ -z "$har_files" ] || [ "$har_files" = "*.har" ]; then
echo "No .har files found."
exit 1
fi
# Iterate over all .har files in the current directory
for file in *.har; do
# Check if the file actually exists
if [ ! -f "$file" ]; then
echo "File not found: $file"
exit 1
fi
# Extract the filename without the extension
base_name=$(basename "$file" .har)
# Initialize an empty string to accumulate all base64 strings
full_base64_string=""
# Extract and concatenate all Base64 strings
while IFS= read -r line; do
full_base64_string+="$line"
done < <(jq -r '.log.entries[] | select(.response.content.mimeType == "audio/aac") | .response.content.text' "$file")
# Check if the full Base64 string is empty
if [ -z "$full_base64_string" ]; then
echo "No AAC content found in $file"
continue # Skip this file but don't stop the whole script
fi
# Decode the concatenated Base64 string and save it to a file
echo "$full_base64_string" | base64 -d > "${base_name}.aac"
# Remove the original .har file
rm "$file"
done
@bmedicke
Copy link
Author

bmedicke commented Mar 9, 2024

Usage:

  • let ChatGPT generate a text
  • open Chrome's network tab (F12), filter for "synthesize"
  • click "Read Aloud", wait until the request has finished loading
  • right click synthesize?message_id=[...] select "Save all as HAR with content"
  • save the file to the same folder as the script and run it ./getGPTune.sh

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment