Skip to content

Instantly share code, notes, and snippets.

@ochafik
Last active January 14, 2025 05:29
Show Gist options
  • Select an option

  • Save ochafik/664b14b7e1fa0189f5a2d5514d9dd84f to your computer and use it in GitHub Desktop.

Select an option

Save ochafik/664b14b7e1fa0189f5a2d5514d9dd84f to your computer and use it in GitHub Desktop.
RPi 5 llama.cpp + Piper TTS continuous hallucination stream
sudo apt update
sudo apt get build-essential git curl cmake
cd
git clone https://github.com/ggerganov/llama.cpp
cd llama.cpp
cmake -B build -DLLAMA_CURL=1 && cmake --build build -j4 -t llama-run -t llama-cli -t llama-server
#./build/bin/llama-run hf://bartowski/Phi-3.5-mini-instruct-GGUF/Phi-3.5-mini-instruct-Q4_0.gguf
#./build/bin/llama-server -fa -ctk q8_0 -ctv q8_0 -mu https://huggingface.co/bartowski/Phi-3.5-mini-instruct-GGUF/resolve/main/Phi-3.5-mini-instruct-Q4_0.gguf
#./build/bin/llama-server -fa -ctk q8_0 -ctv q8_0 -mu https://huggingface.co/bartowski/phi-4-GGUF/resolve/main/phi-4-Q4_0.gguf
cd
wget https://github.com/rhasspy/piper/releases/download/v1.2.0/piper_arm64.tar.gz
tar -zxvf piper_arm64.tar.gz
cd piper
wget https://huggingface.co/rhasspy/piper-voices/resolve/v1.0.0/en/en_GB/alan/medium/en_GB-alan-medium.onnx
wget https://huggingface.co/rhasspy/piper-voices/resolve/v1.0.0/en/en_GB/alan/medium/en_GB-alan-medium.onnx.json
# export MODEL=https://huggingface.co/bartowski/phi-4-GGUF/resolve/main/phi-4-Q4_0.gguf
export MODEL=https://huggingface.co/bartowski/Phi-3.5-mini-instruct-GGUF/resolve/main/Phi-3.5-mini-instruct-Q4_0.gguf
~/github/llama.cpp/build/bin/llama-cli -fa -ctk q8_0 -ctv q8_0 \
-mu "$MODEL" -no-cnv \
-p 'Talk endlessly about life, the universe and whatever inspires you. Do not output formatting, just text that can be spoken.' \
--no-display-prompt 2>/dev/null | \
~/piper/piper --model ~/piper/en_GB-alan-medium.onnx --output-raw | \
aplay -r 22050 -f S16_LE -t raw - -D plughw:2,0
~/github/llama.cpp/build/bin/llama-cli -fa -ctk q8_0 -ctv q8_0 \
-mu "$MODEL" \
--grammar '
char ::= [^"\\\x7F\x00-\x1F] | [\\] (["\\bfnrt] | "u" [0-9a-fA-F]{4})
line ::= "{" "\"text\"" ":" "\"" char{2,100} "\"" "}" "\n"
root ::= line {5,}
' \
-no-cnv \
-p 'Talk endlessly about life, the universe and whatever inspires you. One line at a time (in the format {text: string}), many lines.' \
--no-display-prompt 2>/dev/null | \
~/piper/piper --model ~/piper/en_GB-alan-medium.onnx --json-input --output-raw | \
aplay -r 22050 -f S16_LE -t raw - -D plughw:2,0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment