Initial commit

This commit is contained in:
Zhongwei Li
2025-11-30 08:38:08 +08:00
commit 47031044b5
8 changed files with 558 additions and 0 deletions

View File

@@ -0,0 +1,35 @@
#!/bin/bash
# Download YouTube video in medium quality (720p or lower)
# Usage: ./download-youtube.sh <youtube-url>
if [ -z "$1" ]; then
echo "Error: YouTube URL required"
echo "Usage: $0 <youtube-url>"
exit 1
fi
YOUTUBE_URL="$1"
# Check if yt-dlp is installed
if ! command -v yt-dlp &> /dev/null; then
echo "Error: yt-dlp is not installed"
echo "Install with: pip install yt-dlp"
echo "Or: brew install yt-dlp (macOS)"
echo "Or: sudo apt install yt-dlp (Ubuntu/Debian)"
exit 1
fi
# Download video in medium quality (720p max), output as video.mp4
echo "Downloading YouTube video..."
yt-dlp \
-f "bestvideo[height<=720]+bestaudio/best[height<=720]" \
--merge-output-format mp4 \
-o "video.mp4" \
"$YOUTUBE_URL"
if [ $? -eq 0 ]; then
echo "✓ Video downloaded successfully as video.mp4"
else
echo "Error: Failed to download video"
exit 1
fi

View File

@@ -0,0 +1,23 @@
#!/usr/bin/env bash
# extract-audio.sh - Extract audio from video file for lecture transcription
# Usage: extract-audio.sh <video-file>
set -euo pipefail
VIDEO_FILE="$1"
if [ ! -f "$VIDEO_FILE" ]; then
echo "Error: Video file '$VIDEO_FILE' not found" >&2
exit 1
fi
if ! command -v ffmpeg >/dev/null 2>&1; then
echo "Error: ffmpeg not found" >&2
exit 1
fi
# Extract audio to audio.mp3
ffmpeg -i "$VIDEO_FILE" -vn -acodec libmp3lame -q:a 2 audio.mp3 -y 2>&1 | grep -v "^frame="
echo "Audio extracted: audio.mp3"

View File

@@ -0,0 +1,48 @@
#!/usr/bin/env bash
# transcribe-audio.sh - Transcribe audio using ElevenLabs API
# Usage: transcribe-audio.sh <language-code>
set -euo pipefail
LANGUAGE_CODE="$1"
if [ -z "${ELEVENLABS_API_KEY:-}" ]; then
echo "Error: ELEVENLABS_API_KEY environment variable not set" >&2
exit 1
fi
if [ ! -f "audio.mp3" ]; then
echo "Error: audio.mp3 not found" >&2
exit 1
fi
TEMP_JSON=$(mktemp)
trap "rm -f $TEMP_JSON" EXIT
# Call ElevenLabs API
curl -X POST "https://api.elevenlabs.io/v1/speech-to-text" \
-H "xi-api-key: $ELEVENLABS_API_KEY" \
-F "model_id=scribe_v1" \
-F "file=@audio.mp3" \
-F "language_code=$LANGUAGE_CODE" \
-o "$TEMP_JSON" \
-s
# Check for errors
if ! jq empty "$TEMP_JSON" 2>/dev/null; then
echo "Error: Invalid API response" >&2
cat "$TEMP_JSON" >&2
exit 1
fi
if jq -e '.detail' "$TEMP_JSON" >/dev/null 2>&1; then
echo "API Error:" >&2
jq -r '.detail' "$TEMP_JSON" >&2
exit 1
fi
# Extract and save transcript
jq -r '.text' "$TEMP_JSON" > generated-transcript.txt
echo "Transcript saved: generated-transcript.txt"