Script bash s'arrête avec message ++ cat

Résolu/Fermé
Lume_56 Messages postés 26 Date d'inscription lundi 1 juin 2020 Statut Membre Dernière intervention 20 octobre 2023 - 30 nov. 2022 à 10:25
Lume_56 Messages postés 26 Date d'inscription lundi 1 juin 2020 Statut Membre Dernière intervention 20 octobre 2023 - 5 déc. 2022 à 11:42

Bonjour,

Lorsque j'installe le programme suivant, le script s'arrête ainsi  :

text=$(cat) # get text from stdin into text buffer
++ cat

 C'est la ligne après :

# 2022-02-13 -- Matthias C. Hormann aka Moonbase59
#   - Add sox commands for FR, IT, ES, to prevent error (missing /tmp/foliate-sox.wav).

Qui aurait une explication  pour le message

++ cat

 Merci.

 Je joins le script intégral ci-dessous.

#!/bin/bash -vx
 
# foliate-picotts -- Speak Foliate e-book using PicoTTS and PulseAudio
#
# Requirements:
# - pico2wave -- sudo apt install libttspico-utils
# - paplay -- Most modern systems now use PulseAudio for output
# - sox -- sudo apt install sox
# - sed -- POSIX standard command
#
# Use F5 within Foliate to start/stop speech.
#
# 2021-11-06 -- Matthias C. Hormann aka Moonbase59
#   - Code cleanup, bugfixing, added sox post-processing for better understanding.
#   - Added hypenation (en-dash, em-dash) support.
# 2021-11-09 -- Matthias C. Hormann aka Moonbase59
#   - Fixed paragraph (quoting) problem for pauses between paragraphs.
#   - More code cleanup.
#   - Reduce PicoTTS volume to 60% to avoid clipping.
#   - Added lots of pronunciation hints and corrections.
# 2022-01-01 -- Matthias C. Hormann aka Moonbase59
#   - Final adaption for Foliate as TTS output script.
#   - Added F5 start/stop handling (SIGINT to script by Foliate)
# 2022-02-13 -- Matthias C. Hormann aka Moonbase59
#   - Add sox commands for FR, IT, ES, to prevent error (missing /tmp/foliate-sox.wav).

text=$(cat) # get text from stdin into text buffer

# for debugging only
echo "$text" > /tmp/foliate-picotts.txt

# Remove some oddities inserted by Foliate
# Remove inserted ";"
text=$(echo "$text" | sed 's|; | |g')
# Redo "---" to emdash
text=$(echo "$text" | sed 's|---|—|g')
# Redo "--" to ndash
text=$(echo "$text" | sed 's|--|–|g')
# Redo "...." to dot plus ellipsis
text=$(echo "$text" | sed 's|\.\.\.\.|\.…|g')
# Redo "..." to ellipsis
text=$(echo "$text" | sed 's|\.\.\.|…|g')

# General text preprocessing
# Insert pauses for en- and em-dashes, recognize from<en-dash>to numeric ranges
# en-dash between digits spoken as "bis"
text=$(echo "$text" | sed 's|\([[:digit:]]\{1,\}\)–\([[:digit:]]\{1,\}\)|\1 bis \2|g')
# en-dash with white space around it spoken as a pause
text=$(echo "$text" | sed 's|[[:space:]]–[[:space:]]|<break time="500ms"/>|g')
# em-dash always spoken as a pause
text=$(echo "$text" | sed 's|—|<break time="500ms"/>|g')

# Map Foliate (=ebook) language to PicoTTS language (restricted set)

# for debugging only
echo "$FOLIATE_TTS_LANG_LOWER" > /tmp/foliate-picotts-lang.txt

case "${FOLIATE_TTS_LANG_LOWER:0:2}" in

    "de")
        lang="de-DE"
        # Abbreviations, acronyms and special characters
        # Note: Some are case-sensitive, others not.
        #       Some are full words only, others can be part of other words.
        #       Some can only be pronounced correctly using (XSAMPA) phonemes.
        #       Check RegExp flag "I" and "\b" word boundaries!
        # change "§" ("Paragrafzeichen") -> "Paragraf"
        text=$(echo "$text" | sed 's|§§|Paragrafen |g')
        text=$(echo "$text" | sed 's|§|Paragraf |g')
        # "S." -> "Seite"
        text=$(echo "$text" | sed 's|\bS\.|Seite|g')
        # "ff." -> "und folgende" (as in "S. 23 ff." or "S. 23ff.")
        text=$(echo "$text" | sed -E 's/(\b|[[:digit:]])(ff\.)/\1 und folgende/g')
        # change "Abs." ("Absender") -> "Absatz"
        text=$(echo "$text" | sed 's|\bAbs\.|Absatz|g')
        # "i." as in "Weißenburg i. Bay." -> "in" ("Bay." already recognized as "Bayern")
        text=$(echo "$text" | sed 's|\bi\.|in|g')
        # "Co." ("Compagnon") -> "Co."
        text=$(echo "$text" | sed 's|\bCo\.|Koh|g')
        # "MdB"/"M.d.B." -> "Mitglied des Bundestags"
        text=$(echo "$text" | sed 's|\bM\.d\.B\.|Mitglied des Bundestags|g')
        text=$(echo "$text" | sed 's|\bMdB\b|Mitglied des Bundestags|g')
        # "NASA"
        text=$(echo "$text" | sed 's|\bNASA\b|<phoneme ph=\"\\\"na:.za:\"/>|g')
        # "WLAN"
        text=$(echo "$text" | sed 's|\bWLAN\b|Weh-Lahn|g')
        # MPEG variants
        text=$(echo "$text" | sed 's|\bmpe\?g\b|M peck|gI')
        # JPEG variants
        text=$(echo "$text" | sed 's|\bjpe\?g\b|Tschähpeck|gI')
        # PNG
        text=$(echo "$text" | sed 's|\bpng\b|P N G|gI')
        # MP2, MP3, MP4
        text=$(echo "$text" | sed -E 's/\bmp(2|3|4)\b/M P \1/gI')


        # Other minor corrections
        # "geil"
        text=$(echo "$text" | sed 's|geil|gaihl|gI')
        # "Sex"
        text=$(echo "$text" | sed 's|\bSex\b|<phoneme ph=\"\\\"s\\Eks\"/>|g')
        # "asexuell"
        text=$(echo "$text" | sed 's|\basexuell|a-sexuell|gI')

        # Anglicisms
        # "Wow"
        text=$(echo "$text" | sed 's|\bwow\b|<phoneme ph=\"\\\"v\\a_U:\"/>|gI')
        # "University"
        text=$(echo "$text" | sed 's|\buniversity\b|Juni-Wörßiti|gI')
        # "nature"
        text=$(echo "$text" | sed 's|\bnature\b|Nätscher|gI')
        # "software"
        text=$(echo "$text" | sed 's|\bsoftware\b|ßoftwär|gI')
        # "smartphone"
        text=$(echo "$text" | sed 's|\bsmartphone|Smartphon|gI')
        ;;

    "en")
        lang="en-GB"
        # Abbreviations, acronyms and special characters
        # Note: Some are case-sensitive, others not.
        #       Some are full words only, others can be part of other words.
        #       Some can only be pronounced correctly using (XSAMPA) phonemes.
        #       Check RegExp flag "I" and "\b" word boundaries!
        # "&" ("ampersand") -> "and" (but not for HTML entities like &ndash;
        text=$(echo "$text" | sed 's|[[:blank:]]&[[:blank:]]| and |g')
        # change "§§" ("section section") -> "sections"
        text=$(echo "$text" | sed 's|§§|sections|g')
        # "p." -> "page", "pp." -> "pages"
        text=$(echo "$text" | sed 's|\bpp\.|pages|g')
        text=$(echo "$text" | sed 's|\bp\.|page|g')
        # "ff." -> "and following" (as in "p. 23 ff." or "p. 23ff.")
        text=$(echo "$text" | sed -E 's/(\b|[[:digit:]])(ff\.)/\1 and following/g')
        # "HTML"
        text=$(echo "$text" | sed 's|\bHTML\b|H T M L|g')
        # MPEG variants
        text=$(echo "$text" | sed 's|\bmpe\?g\b|M peg|gI')
        # JPEG variants
        text=$(echo "$text" | sed 's|\bjpe\?g\b|J peg|gI')
        # PNG
        text=$(echo "$text" | sed 's|\bpng\b|P N G|gI')
        # MP2, MP3, MP4
        text=$(echo "$text" | sed -E 's/\bmp(2|3|4)\b/M P \1/gI')

        # Other minor corrections
        ;;

    "fr")
        lang="fr-FR"
        # "Windows" (the operating system)
        text=$(echo "$text" | sed 's|\bwindows\b|<phoneme ph=\"win.doz\"/>|gI')
        # "Linux" (the better operating system)
        text=$(echo "$text" | sed 's|\blinux\b|<phoneme ph=\"li.nyks\"/>|gI')
        ;;

    "it")
        lang="it-IT"
        ;;

    "es")
        lang="es-ES"
        ;;

    *)
        lang="en-US"
        ;;
esac


# reduce volume to avoid clipping
text="<volume level=\"60\">$text</volume>"

# for debugging only
echo "$text" > /tmp/foliate-picotts-finished.txt

# cretae WAV audio file using PicoTTS
pico2wave -l=$lang -w=/tmp/foliate.wav "$text"

# use sox to make output better understandable (voices are rather muffled)
# adding some treble in the range of +3 to +6 dB helps
# some voices might need a little bass reduction, use s/th like "bass -6 400"
# to avoid clipping, give headroom (gain -h) and reclaim afterwards (gain -r)
case "${FOLIATE_TTS_LANG_LOWER:0:2}" in
    "de")
        sox /tmp/foliate.wav /tmp/foliate-sox.wav gain -h treble +6 gain -r
        ;;
    "en")
        sox /tmp/foliate.wav /tmp/foliate-sox.wav gain -h treble +3 gain -r
        ;;
    "fr")
        sox /tmp/foliate.wav /tmp/foliate-sox.wav gain -h treble +3 gain -r
        ;;
    "it")
        sox /tmp/foliate.wav /tmp/foliate-sox.wav gain -h treble +3 gain -r
        ;;
    "es")
        sox /tmp/foliate.wav /tmp/foliate-sox.wav gain -h treble +3 gain -r
        ;;
    *)
        cp /tmp/foliate.wav /tmp/foliate-sox.wav
        ;;
esac

# Prepare cleanup in case we get killed
function cleanup() {
    rm /tmp/foliate.wav
    rm /tmp/foliate-sox.wav
    rm /tmp/foliate-picotts.pid
}

# use PulseAudio to play in the background, remember player's PID
paplay /tmp/foliate-sox.wav > /dev/null & PID=$!
# save PID of player for possible xsay-kill on long texts
echo $PID >/tmp/foliate-picotts.pid

# trap SIGINT (issued by Foliate on 2nd F5)
trap "kill $PID; cleanup; exit 0" INT

# go wait for the spoken output (usually one page)
wait $PID

# Remove temporary files after paplay has finished (or was aborted using xsay-kill)
cleanup


Linux / Firefox 107.0

4 réponses

mamiemando Messages postés 33077 Date d'inscription jeudi 12 mai 2005 Statut Modérateur Dernière intervention 18 avril 2024 7 748
Modifié le 30 nov. 2022 à 16:10

Bonjour,

Comme la première ligne contient -vx, bash te dit au fur et à mesure où il en est. Tu peux ne mettre que #!/bin/bash si tu ne veux pas faire apparaître cette information sur le C++. Ce sont ces informations de débogage qui écrivent "++ cat".

Admettons que ton script corresponde au fichier toto.sh dans le dossier courant (= ./toto.sh). Je suppose qu'à ce stade, tu exécutes ton script comme suit :

./toto.sh

Comme l'indique la ligne sur laquelle le programme est bloqué, le programme s'attend à lire du texte sur stdin. Il est donc lancé en mode interactif et attend que tu tapes du texte à traiter.

De deux choses l'unes :

  • soit tu l'utilises en mode interactif en tapant du texte (tu peux éventuellement passer à la ligne). Quand tu as fini de taper ton texte, tu appuies sur Ctrl+D pour envoyer le caractère fin de fichier (voir ici), et le programme continuera à se dérouler.
  • soit tu utilises ton script à droite d'un pipe où la commande de gauche produit du texte et la commande de droite et ton script :
echo "Bonjour" | ./toto.sh
cat /etc/motd | ./toto.sh

Bonne chance

0
Lume_56 Messages postés 26 Date d'inscription lundi 1 juin 2020 Statut Membre Dernière intervention 20 octobre 2023 1
3 déc. 2022 à 18:03

Bonsoir,

Merci pour tes explications toujours aussi claires. J'ai résolu le problème qui n'en était pas un, en réalité.

Concrètement, le script est utilisé pour transcrire le texte en paroles  (text to speech) des fichiers au format epub lus avec Foliate https://johnfactotum.github.io/foliate/ .

Un problème m'avait obligé à réinstaller la distribution (par chance, le /home était séparé). Je ne rappelais plus qu'il suffisait de recopier le script ou créer un lien symbolique pointant vers /usr/local.bin. Il suffit ensuite de sélectionner le texte pour qu'il soit lu.

Le programme s'attend à lire du texte sur stdin, ce qui correspond au texte sélectionné !

Avec tous mes remerciements !

Foliate
0
mamiemando Messages postés 33077 Date d'inscription jeudi 12 mai 2005 Statut Modérateur Dernière intervention 18 avril 2024 7 748
5 déc. 2022 à 10:03

Merci pour les précisions, même si je n'ai pas saisi l'intérêt de sélectionner le texte pour le faire lire pour ensuite le retranscrire. Il n'aurait pas été plus direct de faire un copier coller ? En tout cas l'important c'est que tu aies résolu ton problème :)

0
Lume_56 Messages postés 26 Date d'inscription lundi 1 juin 2020 Statut Membre Dernière intervention 20 octobre 2023 1
5 déc. 2022 à 10:56

Il n'y a pas de rapport entre les deux. Dans le premier cas que je t'avais soumis, il s'agissait de retranscrire un texte dicté (mail, esquisse de rapport, prises de notes pour un projet, etc. )

Dans le second, il s'agit de faire lire un texte (personnes malvoyantes ou désireuses d'avoir une "lectrice". Cet aspect est prévu dans le cadre plus large d'une présentation de Linux. Je comprends que tu aies établi une relation entre les deux.

0
mamiemando Messages postés 33077 Date d'inscription jeudi 12 mai 2005 Statut Modérateur Dernière intervention 18 avril 2024 7 748
5 déc. 2022 à 11:03

Ah oui d'accord, c'est plus clair maintenant. Peut-être qu'orca peut t'intéresser.

Bonne chance

0
Lume_56 Messages postés 26 Date d'inscription lundi 1 juin 2020 Statut Membre Dernière intervention 20 octobre 2023 1
5 déc. 2022 à 11:42

Merci ! Au plaisir !

0