-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfifo_handler.sh
72 lines (53 loc) · 2.31 KB
/
fifo_handler.sh
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
#!/bin/bash
dir="/home/brilja/Desktop/VChatGPT/tmp/fifos"
p_dir="/home/brilja/Desktop/VChatGPT/tmp/processing"
max_concurrent_processes=15 # Maximum number of concurrent piper processes
declare -A pid_list # Associative array to keep track of running processes
while :; do
readarray -t fifo_files < <(find "$dir" -maxdepth 1 -type f) # Find files in the directory
for fifo_file in "${fifo_files[@]}"; do
if [ ${#pid_list[@]} -lt $max_concurrent_processes ]; then
padded_number=$(echo "$fifo_file" | awk -F '_-_' '{print $2}')
output_file="/home/brilja/Desktop/VChatGPT/tmp/wavs/${padded_number}.wav"
# Read FIFO file content into a variable
fifo_content=$(cat "$fifo_file")
# Start Piper process in the background with FIFO content
echo "$fifo_content" | /home/brilja/piper2/piper/piper --model /home/brilja/piper2/amy/en_US-amy-medium.onnx --output_file "$output_file" &
PID=$!
pid_list[$PID]=$output_file # Map PID to its output file
# Delete the FIFO file
rm "$fifo_file"
fi
done
# Check and clean up completed processes
for pid in "${!pid_list[@]}"; do
if ! kill -0 $pid 2>/dev/null; then # Check if process is no longer running
#rm "${pid_list[$pid]}" # Delete the corresponding FIFO file
unset pid_list[$pid] # Remove PID from the list
fi
done
sleep 0.1 # Small delay before restarting loop
done
# #!/bin/bash
# counter=0
# dir="/home/brilja/Desktop/VChatGPT/tmp/fifos"
# while :; do
# for fifo_file in $dir/*; do
# next_numb=$(printf "%04d" $counter)
# # Start cat and Piper process
# { cat "$fifo_file" | /home/brilja/piper2/piper/piper --model /home/brilja/piper2/amy/en_US-amy-medium.onnx --output_file /home/brilja/Desktop/VChatGPT/tmp/wavs/heyo${next_numb}.wav; } &
# # Capture the PID of the process
# PID=$!
# # Wait for the process to finish
# wait $PID
# # if [ -z "$(ls -A $dir)" ]; then
# # continue #exit the loop
# # fi
# # Increment the counter
# ((counter++))
# # delete the file
# rm "$fifo_file"
# done
# # Optionally, add a small delay before restarting
# sleep 0.1
# done