Created
October 11, 2024 00:35
-
-
Save andrewnc/ec92950fa352739250760e0240a34174 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# ollama run llama3.2:1b | |
# chmod +x talk.sh | |
# ./talk.sh "Your question here" | |
# Check if a question is passed as an argument | |
if [ -z "$1" ]; then | |
echo "Usage: ./talk.sh 'Your question here'" | |
exit 1 | |
fi | |
# Get the user input (the question) | |
QUESTION="$1" | |
# Define the system prompt for natural speech | |
SYSTEM_PROMPT="You are a helpful AI assistant whose output is piped to a text to speech engine. Use '...' for natural pauses where appropriate in your answers." | |
# Make the curl request to the local Ollama model | |
RESPONSE=$(curl -s http://localhost:11434/api/chat -d '{ | |
"model": "llama3.2:1b", | |
"stream": false, | |
"messages": [ | |
{ "role": "system", "content": "'"$SYSTEM_PROMPT"'" }, | |
{ "role": "user", "content": "'"$QUESTION"'" } | |
] | |
}' | jq -r '.message.content') | |
# Check if the response is empty | |
if [ -z "$RESPONSE" ]; then | |
echo "Error: No response from the model." | |
exit 1 | |
fi | |
# Debug: print the response (optional) | |
# echo "Model Response: $RESPONSE" | |
# Convert the response text to speech using edge-tts and play it | |
# check if temp_audio file exists and delete it | |
if [ -f /tmp/temp_audioXXXXXX.mp3 ]; then | |
rm /tmp/temp_audioXXXXXX.mp3 | |
fi | |
tempfile=$(mktemp /tmp/temp_audioXXXXXX.mp3) | |
uvx edge-tts --text "$RESPONSE" --write-media "$tempfile" && afplay "$tempfile" | |
rm "$tempfile" | |
Author
andrewnc
commented
Oct 11, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment