| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239 |
- #!/bin/bash
- # Audio Conversion Script for ZenTap
- # Converts audio files according to specifications in assets/audio/README.md
- set -e # Exit on any error
- # Colors for output
- RED='\033[0;31m'
- GREEN='\033[0;32m'
- YELLOW='\033[1;33m'
- BLUE='\033[0;34m'
- NC='\033[0m' # No Color
- # Directories
- AUDIO_DIR="assets/audio"
- SOURCE_DIR="assets/audio/source"
- MENU_DIR="assets/audio/menu"
- INGAME_DIR="assets/audio/ingame"
- COMPRESSED_DIR="assets/audio/compressed"
- OUTPUT_DIR="assets/audio"
- echo -e "${BLUE}ZenTap Audio Conversion Script${NC}"
- echo "=================================="
- # Check if ffmpeg is installed
- if ! command -v ffmpeg &> /dev/null; then
- echo -e "${RED}Error: ffmpeg is not installed${NC}"
- echo "Please install ffmpeg:"
- echo " Ubuntu/Debian: sudo apt install ffmpeg"
- echo " macOS: brew install ffmpeg"
- echo " Windows: Download from https://ffmpeg.org/download.html"
- exit 1
- fi
- # Create directories if they don't exist
- mkdir -p "$SOURCE_DIR"
- mkdir -p "$MENU_DIR"
- mkdir -p "$INGAME_DIR"
- mkdir -p "$COMPRESSED_DIR"
- mkdir -p "$OUTPUT_DIR"
- echo -e "${YELLOW}Audio Conversion Specifications:${NC}"
- echo "- Sound Effects: MP3 format, 44.1 kHz, 128 kbps, mono, 0.1-0.5 seconds"
- echo "- Menu Music: MP3 format, 44.1 kHz, 192 kbps, stereo, 2-5 minutes"
- echo "- Ingame Music: MP3 format, 44.1 kHz, 192 kbps, stereo, 3-8 minutes"
- echo ""
- # Function to convert sound effects to MP3
- convert_sound_effect() {
- local input_file="$1"
- local output_file="$2"
-
- echo -e "${BLUE}Converting sound effect: $(basename "$input_file")${NC}"
-
- ffmpeg -i "$input_file" \
- -ar 44100 \
- -b:a 128k \
- -ac 1 \
- -t 0.5 \
- -y \
- "$output_file"
-
- if [ $? -eq 0 ]; then
- echo -e "${GREEN}✓ Successfully converted $(basename "$output_file")${NC}"
- else
- echo -e "${RED}✗ Failed to convert $(basename "$input_file")${NC}"
- fi
- }
- # Function to convert background music to MP3
- convert_background_music() {
- local input_file="$1"
- local output_file="$2"
-
- echo -e "${BLUE}Converting background music: $(basename "$input_file")${NC}"
-
- ffmpeg -i "$input_file" \
- -ar 44100 \
- -b:a 192k \
- -ac 2 \
- -y \
- "$output_file"
-
- if [ $? -eq 0 ]; then
- echo -e "${GREEN}✓ Successfully converted $(basename "$output_file")${NC}"
- else
- echo -e "${RED}✗ Failed to convert $(basename "$input_file")${NC}"
- fi
- }
- # Function to validate audio file duration
- validate_duration() {
- local file="$1"
- local expected_min="$2"
- local expected_max="$3"
-
- duration=$(ffprobe -v quiet -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 "$file" 2>/dev/null)
-
- if [ $? -eq 0 ] && [ -n "$duration" ]; then
- # Convert to integer using awk for better compatibility
- duration_int=$(echo "$duration" | awk '{print int($1)}')
- if [ "$duration_int" -ge "$expected_min" ] && [ "$duration_int" -le "$expected_max" ]; then
- echo -e "${GREEN}✓ Duration validation passed: ${duration}s${NC}"
- else
- echo -e "${YELLOW}⚠ Duration warning: ${duration}s (expected ${expected_min}-${expected_max}s)${NC}"
- fi
- else
- echo -e "${YELLOW}⚠ Could not validate duration${NC}"
- fi
- }
- echo -e "${YELLOW}Looking for source files in $SOURCE_DIR${NC}"
- echo ""
- # Convert sound effects
- for sound_effect in "bubble_pop" "bubble_pop_alt" "ambient_background"; do
- # Look for various input formats
- for ext in wav mp3 ogg flac m4a; do
- source_file="$SOURCE_DIR/${sound_effect}.$ext"
- if [ -f "$source_file" ]; then
- output_file="$SOURCE_DIR/${sound_effect}.mp3"
- if [[ "$sound_effect" == "ambient_background" ]]; then
- convert_background_music "$source_file" "$output_file"
- if [ -f "$output_file" ]; then
- validate_duration "$output_file" 120 300 # 2-5 minutes
- fi
- else
- convert_sound_effect "$source_file" "$output_file"
- if [ -f "$output_file" ]; then
- validate_duration "$output_file" 0 1
- fi
- fi
- echo ""
- break
- fi
- done
- done
- # Convert menu music files
- echo -e "${YELLOW}Converting menu music files...${NC}"
- for theme in "default" "spring" "summer" "autumn" "winter"; do
- for ext in wav mp3 ogg flac m4a; do
- source_file="$SOURCE_DIR/menu_${theme}.$ext"
- if [ -f "$source_file" ]; then
- output_file="$MENU_DIR/menu_${theme}.mp3"
- convert_background_music "$source_file" "$output_file"
-
- if [ -f "$output_file" ]; then
- validate_duration "$output_file" 120 300 # 2-5 minutes
- fi
- echo ""
- break
- fi
- done
- done
- # Convert ingame music files
- echo -e "${YELLOW}Converting ingame music files...${NC}"
- for theme in "default" "spring" "summer" "autumn" "winter"; do
- for track_num in "001" "002" "003"; do
- for ext in wav mp3 ogg flac m4a; do
- source_file="$SOURCE_DIR/ingame_${theme}_${track_num}.$ext"
- if [ -f "$source_file" ]; then
- output_file="$INGAME_DIR/ingame_${theme}_${track_num}.mp3"
- convert_background_music "$source_file" "$output_file"
-
- if [ -f "$output_file" ]; then
- validate_duration "$output_file" 180 480 # 3-8 minutes
- fi
- echo ""
- break
- fi
- done
- done
- done
- # Check if we have any missing files
- echo -e "${YELLOW}Checking for required audio files:${NC}"
- echo -e "${BLUE}Sound Effects (source/):${NC}"
- sound_effect_files=(
- "source/bubble_pop.mp3"
- "source/bubble_pop_alt.mp3"
- "source/ambient_background.mp3"
- )
- echo -e "${BLUE}Menu Music (menu/):${NC}"
- menu_music_files=(
- "menu/menu_default.mp3"
- "menu/menu_spring.mp3"
- "menu/menu_summer.mp3"
- "menu/menu_autumn.mp3"
- "menu/menu_winter.mp3"
- )
- echo -e "${BLUE}Ingame Music (ingame/):${NC}"
- ingame_music_files=(
- "ingame/ingame_default_001.mp3"
- "ingame/ingame_spring_001.mp3"
- "ingame/ingame_summer_001.mp3"
- "ingame/ingame_autumn_001.mp3"
- "ingame/ingame_winter_001.mp3"
- "ingame/ingame_winter_002.mp3"
- )
- all_files=("${sound_effect_files[@]}" "${menu_music_files[@]}" "${ingame_music_files[@]}")
- missing_files=()
- for file in "${all_files[@]}"; do
- if [ -f "$AUDIO_DIR/$file" ]; then
- echo -e "${GREEN}✓ $file${NC}"
- else
- echo -e "${RED}✗ $file (missing)${NC}"
- missing_files+=("$file")
- fi
- done
- echo ""
- if [ ${#missing_files[@]} -eq 0 ]; then
- echo -e "${GREEN}All audio files are present!${NC}"
- else
- echo -e "${YELLOW}Missing files: ${#missing_files[@]} out of ${#all_files[@]}${NC}"
- echo ""
- echo -e "${BLUE}To add missing files:${NC}"
- echo "1. Place source audio files in $SOURCE_DIR/ with appropriate names"
- echo "2. Run this script again"
- echo ""
- echo -e "${BLUE}Expected source file naming:${NC}"
- echo "- Sound effects: bubble_pop.*, bubble_pop_alt.*, ambient_background.*"
- echo "- Menu music: menu_default.*, menu_spring.*, menu_summer.*, menu_autumn.*, menu_winter.*"
- echo "- Ingame music: ingame_<theme>_<track>.* (e.g., ingame_winter_001.mp3)"
- echo ""
- echo -e "${BLUE}Supported source formats:${NC} WAV, MP3, OGG, FLAC, M4A"
- fi
- echo ""
- echo -e "${BLUE}Audio conversion complete!${NC}"
|