-
-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathvoice_client_local
More file actions
executable file
·94 lines (82 loc) · 3.14 KB
/
voice_client_local
File metadata and controls
executable file
·94 lines (82 loc) · 3.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/bin/bash
# Copyright (C) 2026 by Henry Kroll III, www.thenerdshow.com
#
# With code contributions by Matthew Rensberry
#
# This is free software. You may redistribute it under the terms
# of the Apache license and the GNU General Public License Version
# 2 or at your option any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public
# License along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#
# fifo queue to hold temporary audio file names
audio_fifo=$(mktemp); rm "$audio_fifo" ; mkfifo "$audio_fifo"
# flag parsing
use_flow=false
if [[ "$1" == "-flow" ]]; then
use_flow=true
fi
# start whisper service
systemctl --user start whisper.service
# tab away
# sleep 0.25 && ydotool key 56:0 42:0 56:1 15:1 56:0 15:0
## create a trap to remove temp files, stop server on untimely exit
cleanup() {
systemctl --user stop whisper.service
rm -f /tmp/tmp.txt "$audio_fifo"
}
trap cleanup 0
# function to process audio files from queue
trans(){
while read audio; do
# Send audio file to whisper.cpp using curl
curl_output=$(curl -s "http://127.0.0.1:7777/inference" \
-H "Content-Type: multipart/form-data" \
-F "file=@$audio" \
-F "temperature=0.2" \
-F "response-format=json")
# Parse JSON to extract text
extracted_text=$(echo "$curl_output" | jq -r '.text')
# remove temporary audio file
rm -f "$audio"
echo "$extracted_text"
# Type text to terminal, in background
# Thanks for watching! seems to occur frequently due to noise.
if [[ ${#extracted_text} > 15 ]] && ! [[ "$extracted_text" =~ "Thanks for watching" ]] \
&& ! [[ "$extracted_text" =~ '[' ]]; then
if [ "$use_flow" = true ]; then
ydotool type $(llama_edit "$extracted_text")
else
ydotool type "$extracted_text"
fi
fi &
done < "$audio_fifo"
#cleanup
rm -f "$audio_fifo"
}
# record audio in background
while true; do
# Make temporary files to hold audio
tmp=$(mktemp)
# Remove it on exit
trap 'rm "$tmp" ; exit' INT
# Listen to the mic.
# The `1 0.2 6%` part of this command trims one clip of silence
# from the beginning. 6% of max volume is considered silence here.
# `1 1.0 8%` stops after a 1.0 second pause in speech.
# If recording never stops, increase sound threshold from 8%
# to 10% or more. This can happen with poor recording equipment
# or noisy environments with heaters and fans going.
rec -c 1 -r 22050 -t mp3 "$tmp" silence 1 0.2 6% 1 1.0 8%
# echo temporary audio file name to transcription queue
echo "$tmp"
done > "$audio_fifo" & #The `&` lets recording run in the background.
# run audio transciption handler
trans