Skip to content

Instantly share code, notes, and snippets.

@Brandon7CC
Created December 29, 2023 23:38
Show Gist options
  • Save Brandon7CC/29fad35e4d2a5f07693c3990ca4946af to your computer and use it in GitHub Desktop.
Save Brandon7CC/29fad35e4d2a5f07693c3990ca4946af to your computer and use it in GitHub Desktop.
📣 Giving Ollama a voice with the macOS `say` command! NOTE: Change to Siri in `System Settings.app` for the best results.
function speak_ollama() {
if ! command -v ollama &> /dev/null; then
echo "Error: ollama is not installed."
return 1
fi
if [ "$#" -ne 2 ]; then
echo "Usage: speak_ollama <file_path> <model>"
return 1
fi
local file_path="$1"
local model="$2"
if [ ! -f "$file_path" ]; then
echo "Error: File not found at $file_path"
return 1
fi
local prompt=$(cat "$file_path")
local completion=$(ollama run "$model" "$prompt")
say "$completion" --progress --rate=180
}
@Brandon7CC
Copy link
Author

Brandon7CC commented Dec 29, 2023

Usage

❯ speak_ollama
Usage: speak_ollama <file_path> <model>

One liner

Adds the function to your ~/.zshrc.

curl -sL https://gist.githubusercontent.com/Brandon7CC/29fad35e4d2a5f07693c3990ca4946af/raw/edde21dace26bfd91b43b4e1fa82f4b373fd1689/speak_ollama.sh >> ~/.zshrc && source ~/.zshrc

Screenshot 2024-01-13 at 6 38 35 PM

@MikeyBeez
Copy link

If you have bluetooth speakers, you may experience words being cut-off. Mac bluetooth sucks.

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