
Estou na plataforma Ubuntu 22.04. Eu criei uma GUI de botão simples em c chamada t2s
e coloquei-a em ~/.local/bin
cujo caminho é adicionado à PATH
variável de ambiente. Enquanto pressiono o botão, ele grava a voz do microfone em um arquivo temporário. Quando eu solto o botão, a GUI sai. Eu executo a seguinte linha que funciona bem no terminal:
t2s && notify-send -u normal -t 10000 "$( whispercpp -m /home/****/Desktop/2022-10/whisper.cpp/models/ggml-small.bin -nt -l tr -f /dev/shm/mic.wav )"
A voz é enviada para whispercpp
fala para mecanismo de texto e transcrita. O resultado é mostrado na notificação na tela.
Mas quando coloco essa linha em um arquivo e o inicio, como:
#!/bin/bash
t2s && notify-send -u normal -t 10000 "$( whispercpp -m /home/****/Desktop/2022-10/whisper.cpp/models/ggml-small.bin -nt -l tr -f /dev/shm/mic.wav )"
exit 0
ele só executa o botão GUI, quando a GUI sai após soltar o botão, ele não executa
notify-send -u normal -t 10000 "$( whispercpp -m /home/****/Desktop/2022-10/whisper.cpp/models/ggml-small.bin -nt -l tr -f /dev/shm/mic.wav )"
papel
O que estou fazendo de errado?
EDITAR:
Eu também tentei assim:
#!/bin/bash
t2s
TEXT=$( whispercpp -m /home/****/Desktop/2022-10/whisper.cpp/models/ggml-small.bin -nt -l tr -f /dev/shm/mic.wav )"
notify-send -u normal -t 10000 $TEXT
Nada mudou.
EDITAR:
Percebi que está relacionado aos componentes internos do shell.
- https://stackoverflow.com/questions/81520/how-to-suppress-terminated-message-after-killing-in-bash
- https://stackoverflow.com/questions/32551713/how-can-i-silence-the-terminated-message-when-my-command-is-killed-by-timeout
- https://unix.stackexchange.com/questions/65902/why-does-bash-show-terminated-after-killing-a-process
Ainda não sei como superar isso.
Responder1
Depois de ler os seguintes links:
Eu entendi que o encerramento da ffmpeg
linha que foi executada GUI button
faz com que o shell bash termine após t2s
a GUI. Resolvi o problema conversando SIGINT
e SIGTERM
sinalizando dentro de um trap
bloco e, em seguida, coloquei o restante dos comandos nele depois t2s
:
#!/bin/bash
trap_with_arg() { # from https://stackoverflow.com/a/2183063/804678
local func="$1"; shift
for sig in "$@"; do
trap "$func $sig" "$sig"
done
}
stop() {
trap - SIGINT EXIT
printf '\n%s\n' "received $1, killing child processes"
notify-send -u normal -t 10000 "$(whispercpp -m /home/**/Desktop/2022-10/whisper.cpp/models/ggml-small.bin -nt -l tr -f /dev/shm/mic.wav )"
kill -s SIGINT 0
}
trap_with_arg 'stop' EXIT SIGINT SIGTERM SIGHUP
t2s
exit 0