#!/bin/bash # Set the default recording duration to 3600 seconds (1 hour) if not set RECORD_DURATION=${RECORD_DURATION:-10} # Set the default recorder to sox if not set RECORDER=${RECORDER:-arecord} # Function to record and convert audio record_audio() { while true; do # Create the directory with the current date current_date=$(date +"%Y-%m-%d") mkdir -p "$current_date" # Get the current time current_time=$(date +"%H-%M-%S") file_path="$current_date/recording_${current_date}_${current_time}.wav" # Record audio for the specified duration if [ "$RECORDER" = "sox" ]; then sox -d -t wav - trim 0 "$RECORD_DURATION" -c 2 -r 44100 "$file_path" elif [ "$RECORDER" = "arecord" ]; then arecord -f cd -d "$RECORD_DURATION" "$file_path" else echo "Unknown recorder: $RECORDER" exit 1 fi # Convert the recorded WAV file to MP3 using ffmpeg ffmpeg -i "$file_path" "${file_path%.wav}.mp3" # Remove the WAV file after conversion rm "$file_path" done } # Start recording audio record_audio