diff options
author | ben | 2025-01-15 20:42:44 +0100 |
---|---|---|
committer | ben | 2025-01-15 20:42:44 +0100 |
commit | 6c1b211260463332f6858fe0a65a733120dfba66 (patch) | |
tree | 9df9bb4b45d37fb01fa1948a557ebed4ba1b495e /tools/stt.sh | |
parent | 947ee3cba20750adf842f366bc85ead31b573b21 (diff) | |
download | ai_env-6c1b211260463332f6858fe0a65a733120dfba66.tar.gz ai_env-6c1b211260463332f6858fe0a65a733120dfba66.tar.bz2 ai_env-6c1b211260463332f6858fe0a65a733120dfba66.tar.xz |
Cleaning up scripts for speech functions
Diffstat (limited to 'tools/stt.sh')
-rwxr-xr-x | tools/stt.sh | 121 |
1 files changed, 0 insertions, 121 deletions
diff --git a/tools/stt.sh b/tools/stt.sh deleted file mode 100755 index 13a1b5a..0000000 --- a/tools/stt.sh +++ /dev/null @@ -1,121 +0,0 @@ -#!/bin/bash - -# Function to print usage information -usage() { - echo "Usage: $0 [record|transcription] <options>" - echo "" - echo "Actions:" - echo " record Record audio from a selected source" - echo " transcription Transcribe audio from a .wav file" - echo "" - echo "Options for 'record':" - echo " -s, --source Specify the audio source (required)" - echo "" - echo "Options for 'transcription':" - echo " -f, --file Specify the audio file to transcribe (required)" - echo " -l, --lang Specify the audio file language (default: en)" - exit 1 -} - -if [[ $# -eq 0 ]]; then - usage -fi - -# Check for required environment variable -if [[ -z "${LLM_API_KEY}" ]]; then - echo "The environment variable LLM_API_KEY is not set." - echo 'You can use the following command: export $(xargs < ../.env))' - exit 1 -fi - -ACTION=$1 -shift - -host=${STT_API_HOST:-"http://localhost:8001"} -LANG="en" # Default language - -if [ "$ACTION" == "record" ]; then - if [ "$#" -eq 0 ]; then - echo "Error: Source is required for record action." - echo "Available sources:" - pactl list short sources | awk '{print $2}' - exit 1 - fi - - SOURCE="" - while [[ "$#" -gt 0 ]]; do - case $1 in - -s | --source) - SOURCE="$2" - shift - ;; - *) - echo "Unknown parameter passed: $1" - usage - ;; - esac - shift - done - - # Validate the provided source - if ! pactl list short sources | awk '{print $2}' | grep -q "^$SOURCE$"; then - echo "Error: Invalid audio source. Available sources:" - pactl list short sources | awk '{print $2}' - exit 1 - fi - - timestamp=$(date +"%Y%m%d_%H%M%S") - filename="record_${timestamp}.wav" - echo "Start recording to ${filename} ; use CTRL+C to terminate." - parec -d "${SOURCE}" --file-format=wav "${filename}" -elif [ "$ACTION" == "transcription" ]; then - if [ "$#" -eq 0 ]; then - echo "Error: File is required for transcription action." - usage - fi - - FILE="" - while [[ "$#" -gt 0 ]]; do - case $1 in - -f | --file) - FILE="$2" - shift - ;; - -l | --lang) - LANG="$2" - shift - ;; - *) - echo "Unknown parameter passed: $1" - usage - ;; - esac - shift - done - - if [ -z "$FILE" ]; then - echo "Error: File is required for transcription action." - usage - fi - - # Check if the file exists - if [ ! -f "$FILE" ]; then - echo "Error: File '$FILE' does not exist." - exit 1 - fi - - # Ensure that curl is available - if ! command -v curl &>/dev/null; then - echo "curl is required for transcription but could not be found on your system. Please install it." - exit 1 - fi - - # Transcribe the specified file - echo "Transcribing file $FILE, be patient" - curl "${host}/v1/audio/transcriptions" -H "Authorization: Bearer ${LLM_API_KEY}" \ - -F "file=@${FILE}" \ - -F "stream=true" \ - -F "language=${LANG}" -else - usage -fi |