Error occurred getting terminal width. Error: inappropriate ioctl for device

I know this issue may not be related to it being a docker container but i cant find any answers anywhere else so im just asking here. So im trying to run this .sh script but whenever i do i get the error in the title

#!/bin/bash

if [ "$#" -ne 1 ]; then
    echo "Usage: $0 'prompt for tgpt'"
    exit 1
fi

PROMPT="$1"
echo "Running tgpt with prompt: $PROMPT"

TGPT_OUTPUT=$(tgpt --provider opengpts "$PROMPT")
echo "tgpt output: $TGPT_OUTPUT"

#Ensure Piper model file exists
PIPER_MODEL="/voiceModels/en_US-libritts_r-medium.onnx"
if [ ! -f "$PIPER_MODEL" ]; then
    echo "Piper model not found: $PIPER_MODEL"
    exit 1
fi

#Generate speech from the tgpt output
echo "Running piper with model: $PIPER_MODEL"
echo "$TGPT_OUTPUT" | piper --model "$PIPER_MODEL" --output_file /outputs/output.wav

#Check if the output file was created
if [ -f /outputs/output.wav ]; then
    echo "Speech synthesis complete. Output saved to /outputs/output.wav"
else
    echo "Failed to create output file."
fi

and if i run the tgpt command instead of the script it works so i assume the problem is the script.

Any help would be appreciated thanks!

I can’t tell you what’s wrong with your script.

Though, you should consider adding -eux to the shebang to get an idea which exact command causes the problem.

#!/bin/bash -eux

Roughly the settings translate to:
e = exit on error (~=fail fast)
u = accessing unassigned variable throws error
x = debug

Since you already have echos in place before and after every command, you must already know which command actually causes the problem. Don’t you agree that it would be helpful to have shared which of those lines causes the problem?

1 Like

Sorry i should have included the full output, that is my bad.
Anyways this is the full output now after adding -eux

docker run --rm -it -v C:\Users\Devilmuffin\Documents\dockerChatBot\outputs:/outputs dockerchatbot bash -c "/app/tgptPiperOutput.sh 'What is 72 + 34'"
+ '[' 1 -ne 1 ']'
+ PROMPT='What is 72 + 34'
+ echo 'Running tgpt with prompt: What is 72 + 34'
Running tgpt with prompt: What is 72 + 34
++ tgpt --provider opengpts 'What is 72 + 34'
          PUT='
Error occurred getting terminal width. Error: inappropriate ioctl for device'
          pt output:
Error occurred getting terminal width. Error: inappropriate ioctl for device'
          t:
Error occurred getting terminal width. Error: inappropriate ioctl for device
+ PIPER_MODEL=/voiceModels/en_US-libritts_r-medium.onnx
+ '[' '!' -f /voiceModels/en_US-libritts_r-medium.onnx ']'
+ echo 'Running piper with model: /voiceModels/en_US-libritts_r-medium.onnx'
Running piper with model: /voiceModels/en_US-libritts_r-medium.onnx

Error occurred getting terminal width. Error: inappropriate ioctl for device'
+ piper --model /voiceModels/en_US-libritts_r-medium.onnx --output_file /outputs/output.wav
[2024-06-10 15:22:45.848] [piper] [info] Loaded voice in 0.667626108 second(s)
[2024-06-10 15:22:45.848] [piper] [info] Initialized piper
/outputs/output.wav
[2024-06-10 15:22:48.590] [piper] [info] Real-time factor: 0.06245848925198228 (infer=2.720731448 sec, audio=43.56063492063492 sec)
[2024-06-10 15:22:48.591] [piper] [info] Terminated piper
+ '[' -f /outputs/output.wav ']'
+ echo 'Speech synthesis complete. Output saved to /outputs/output.wav'
Speech synthesis complete. Output saved to /outputs/output.wav

Also the thing it outputs is just i think like an auto generated output if there was no input or something so that part doesnt actually matter i dont think but i will include all of the output