Audio ও Music generation
এই পাঠে যা শিখবেন
- Audio data কীভাবে represent — waveform, spectrogram, mel
- WaveNet, HiFi-GAN, Tacotron, FastSpeech — TTS-এর evolution
- MusicGen, AudioLDM, Suno — text-to-music architecture
- torchaudio ও HuggingFace দিয়ে বাংলা TTS — হাতে-কলমে কোড
১ · Audio কীভাবে represent করি
একটি অডিও ফাইল = সময়ের সাথে বাতাসের চাপের পরিবর্তন → সংখ্যায় রূপান্তর। Sample rateSample rateপ্রতি সেকেন্ডে কতবার waveform sample নেওয়া হয়। 16kHz speech-এ standard, 44.1kHz music-এ CD quality, 48kHz video-তে। ১৬kHz = ১ সেকেন্ড → ১৬,০০০ float sample। ১ মিনিট ≈ ১M sample।
- Waveform domain: raw amplitude over time।
- Spectrogram (STFT): short-time Fourier transform → time × frequency grid।
- Mel-spectrogram: human ear-aligned frequency bin (low-freq sensitive)।
- Discrete tokens (EnCodec, SoundStream): neural codec → audio → discrete token sequence → LLM-এর মতো model করা যায়।
২ · WaveNet (van den Oord 2016) — direct waveform
DeepMind-এর WaveNet প্রথম high-quality neural audio দিল। Architecture: dilated causal convolution। প্রতি sample-এর জন্য আগের ১০,০০০ sample-এ condition করে — autoregressive।
$$P(\mathbf{x}) = \prod_{t=1}^{T} P(x_t \mid x_1, \ldots, x_{t-1})$$
১৬kHz-এ ১ সেকেন্ড = ১৬,০০০ forward pass — খুব ধীর। তাই HiFi-GAN, Parallel WaveGAN — distill versions দ্রুত।
১) Text → phoneme: "ঢাকা" → /ɖʱaːkaː/।
২) Acoustic model: Tacotron 2 / FastSpeech 2 → mel-spectrogram।
৩) Vocoder: HiFi-GAN / WaveGlow → waveform।
৪) End-to-end (২০২৩+): VITS, XTTS, StyleTTS — সব এক model-এ।
৩ · Music generation — MusicGen, AudioLDM, Suno
- MusicGen (Meta 2023, Copet et al.): EnCodec দিয়ে audio → discrete token; transformer LM token predict করে। Text condition → instrumental music।
- AudioLDM (২০২৩): latent diffusion — Stable Diffusion-এর audio variant। CLAP (audio CLIP) দিয়ে text condition।
- Suno, Udio (২০২৪): end-to-end song generation — vocals সহ। Architecture closed; rumored — token-based LM + diffusion vocoder।
৪ · বাংলা TTS — torchaudio হাতে-কলমে
Bangla TTS এখনো কম mature। তবে কয়েকটি option:
- BUET CSE-র Bangla TTS।
- Coqui TTS (XTTS-v2): multilingual, voice clone সহ।
- Google Cloud TTS, Azure TTS: production-grade Bangla।
- OpenAI TTS: Bangla limited support।
# pip install TTS
from TTS.api import TTS
# multilingual XTTS — বাংলা কাজ করে (limited)
tts = TTS("tts_models/multilingual/multi-dataset/xtts_v2", gpu=True)
text = "বাংলাদেশের প্রতিটি গ্রাম থেকে শহর পর্যন্ত AI পৌঁছে যাবে।"
tts.tts_to_file(
text=text,
speaker_wav="reference_speaker.wav", # voice clone
language="bn",
file_path="output_bn.wav",
)
print("✅ saved output_bn.wav")
৫ · MusicGen দিয়ে সংগীত
from transformers import MusicgenForConditionalGeneration, AutoProcessor
import scipy.io.wavfile
processor = AutoProcessor.from_pretrained("facebook/musicgen-small")
model = MusicgenForConditionalGeneration.from_pretrained("facebook/musicgen-small")
inputs = processor(
text=["upbeat folk music with sarod and tabla, Bangladesh village vibe"],
padding=True, return_tensors="pt",
)
audio = model.generate(**inputs, max_new_tokens=512) # ~10s audio
scipy.io.wavfile.write("musicgen_output.wav",
rate=model.config.audio_encoder.sampling_rate,
data=audio[0, 0].cpu().numpy())
print("🎵 saved musicgen_output.wav")
ভাবনার প্রশ্ন
প্র ০১ Audio-তে raw waveform predict (WaveNet) বনাম mel-spectrogram + vocoder (Tacotron)। Trade-off কী? কেন আজকের mainstream দ্বিতীয় পথে?
Audio generation-এ representation-এর choice — quality, speed, controllability সব নির্ধারণ করে।
Raw waveform (WaveNet, ২০১৬):
- ✅ Lossless — original signal-ই predict।
- ✅ Architecturally simple — no two-stage error propagation।
- ❌ ১৬,০০০ Hz = ১ সেকেন্ডে ১৬K autoregressive step। GPU-তেও ২-৪ সেকেন্ড audio generate-এ মিনিট।
- ❌ Long-range dependency model করা কঠিন — phoneme spans hundreds of samples।
Mel-spectrogram + vocoder (Tacotron, FastSpeech):
- ✅ Mel-spectrogram = ৮০ × ৮০০ frame for ১০ second — much fewer tokens।
- ✅ Acoustic model phoneme-level pattern শিখে; vocoder shape তৈরিতে focused।
- ✅ Vocoder reusable — TTS, voice conversion, music সব জায়গায়।
- ❌ Two-stage error: mel imperfect → vocoder amplify।
- ❌ Mel-spec থেকে exact reconstruction impossible (phase information হারায়)।
আজকের state-of-the-art:
- VITS (২০২১): end-to-end — text → waveform direct, কিন্তু internally still mel-like latent।
- EnCodec / SoundStream: neural codec — audio → discrete tokens → LM-style modeling। MusicGen, Bark এই path-এ।
- Latent diffusion (AudioLDM, Stable Audio): mel latent space-এ diffuse। Image-এর সাফল্য audio-তে।
Modern context:
- Token-based approach (EnCodec + transformer) — text generation infrastructure reuse।
- Diffusion approach — image-এর পাকা technique copy।
- End-to-end VALL-E (Microsoft 2023) — ৩-second prompt → voice clone।
মূল উপলব্ধি: "Direct" model conceptually সুন্দর কিন্তু practical নয়। Hierarchical representation — coarse-to-fine — quality এবং efficiency দু'টোই দেয়।
প্র ০২ একটি বাংলা audiobook startup বানাচ্ছেন। কোন TTS engine বাছবেন? Costs, voice quality, dialect coverage, censorship — সব মিলিয়ে।
Audiobook-এ TTS quality non-negotiable — শ্রোতা ১০ ঘণ্টা শুনবে। সামান্য robotic touch-ও বিরক্তিকর।
Option-গুলো:
- Google Cloud TTS Bangla: ₹১৬/M character ($16/M)। Quality decent — neural voice "bn-IN-Wavenet-A/B/C/D"। Bangladeshi accent কম, Indian accent dominant।
- Azure Speech (Bangla-IN, Bangla-BD): Bangladesh accent better — Pradeep, Nabanita voices। $16/M character।
- OpenAI TTS: "alloy", "nova" Bangla এ functional but not great pronunciation।
- ElevenLabs: $5-$330/month। Voice clone। Bangla support emerging।
- Self-hosted XTTS-v2 (Coqui): Free + GPU cost। Voice clone। Quality ~70% commercial।
- BUET / Bangla TTS open-source: Bangladesh-native pronunciation কিন্তু voice options সীমিত।
আমার সুপারিশ phased:
- MVP: Azure Bangla-BD voice — quality acceptable, scale ready।
- Differentiation: ElevenLabs দিয়ে narrator voice clone (legal consent সহ) — branded "voice"।
- Cost optimization: Volume বাড়লে self-host XTTS, fine-tune bnTTS।
Edge cases:
- Pronunciation: "যশোর", "ফরিদপুর" সব TTS misread করে। Lexicon override করতে হবে।
- Dialect: Sylheti, Chittagonian — কোনো commercial TTS handle করে না।
- Code-switching: "এই product-টা amazing" — TTS English-Bangla mix-এ struggle।
- Numerals: "১২৩" বনাম "123" — pronunciation ভিন্ন।
- Censorship/safety: কিছু provider sensitive content block। Audiobook-এ rare problem কিন্তু check করুন।
Cost estimate:
- একটি বই ~৩০০ পৃষ্ঠা = ~৫,০০,০০০ character → Azure: $8/বই।
- Self-host: GPU $0.50/hour × ১০ hour render = $5/বই।
- Catalog ১,০০০ বই → $৫,০০০-$৮,০০০ + voice talent licensing।
মূল কথা: TTS commodity হয়ে গেছে — পার্থক্য তৈরি হয় voice, dialect coverage, ও Bangla-specific tuning-এ। এখানেই startup-এর moat।
প্র ০৩ MusicGen ও Suno copyright চ্যালেঞ্জ — কীভাবে train? "Style of Beatles" ban কেন? Music industry কীভাবে react করছে?
Music AI-এর copyright situation tense — RIAA, music labels সক্রিয় lawsuit-এ।
Training data সমস্যা:
- MusicGen Meta-এর ২০K hour licensed music — "owned or licensed" বলেছে।
- Suno, Udio — undisclosed but RIAA lawsuit (2024) দাবি করছে copyright music ছাড়াই train।
- Court documents-এ Suno-র CEO admit করেছে — "millions of recordings" used।
Fair use argument:
- OpenAI/Suno দাবি — "transformative use" (Authors Guild v Google Books-এর similar)।
- Music industry counter — output-ও commercial substitution তৈরি করছে।
- ২০২৪-এ কোনো rul নেই — pending।
Why "style of Beatles" blocked:
- Right of publicity — artist-এর identity commercially use। US-এ state law।
- Drake-Kendrick AI track "Heart on My Sleeve" — UMG DMCA-তে remove।
- Suno explicit-এ artist name reject; subtle prompt-এ ("90s grunge") allow।
Music industry response:
- Sue (RIAA, Universal, Sony, Warner vs Suno/Udio, June 2024): $150K per work damages claim।
- License (YouTube + Universal): AI music training license deal।
- Detection (Audible Magic): AI music identify করার tool।
- Watermarking: Stable Audio-তে inaudible signature।
- Embrace (Grimes): "use my voice, share royalty 50/50"।
Bangladesh context:
- Copyright Act 2000 + amendments — কিন্তু AI-specific provision নেই।
- Bangla folk, Rabindra Sangeet — public domain বনাম BPCS, Visva-Bharati estate দাবি।
- Local artists (James, Shironamhin) — voice clone case হলে legal route এখনো অস্পষ্ট।
Modern path forward:
- Licensed datasets (Splice, BeatBread)।
- Synthetic music for AI training।
- "Opt-in" artist marketplace।
- EU AI Act-এ training data disclosure requirement।
মূল উপলব্ধি: Music AI technical breakthrough — কিন্তু legal-economic ecosystem এখনো settle হয়নি। যিনি দু'দিকে balance করতে পারবেন — তিনি এই space-এ winner।
প্র ০৪ Real-time voice conversation (যেমন GPT-4o voice mode) — latency target কত? Pipeline কোথায় bottleneck? Bangladesh থেকে কেন slow?
Real-time voice = "feel like human"। Human conversation-এ ২০০ms turn-taking pause; ১ second-এর বেশি awkward।
Naive pipeline (cascade):
- VAD (voice activity detection) — ১০০-২০০ms wait for end-of-speech।
- STT (Whisper) — ৩০০-৫০০ms।
- LLM (GPT-4) — ৫০০-৩০০০ms first token + streaming।
- TTS — first audio chunk ৩০০-৫০০ms।
- Network round-trip (BD → US) — ২৫০-৪০০ms।
- Total: ১.৫-৪ second। Awkward।
GPT-4o voice (mid-2024):
- End-to-end multimodal — audio token → audio token, no text intermediate।
- Latency ~৩২০ms — human-like।
- Tradeoff — control কম (TTS voice fix না)।
Bangladesh-specific bottleneck:
- Network: Submarine cable BD → Singapore/India → US → ১৫০-২৫০ms one-way।
- Provider edge: OpenAI Singapore/Mumbai PoP — ৬০-৯০ms।
- 3G/4G mobile: additional ১০০-৩০০ms jitter।
- Bangla TTS quality: additional STT/TTS hop।
Optimization কৌশল:
- Streaming everywhere: STT word-by-word, LLM token-by-token, TTS chunk-by-chunk।
- Speculative execution: partial transcript-এ LLM start।
- Edge inference: small model (Whisper tiny, Llama 3B) on phone।
- Cached fillers: "ঠিক আছে...", "একটু দাঁড়ান..." pre-generated।
- Local PoP: Singapore region-এ deploy।
Production metrics:
- TTFB (time-to-first-byte audio) < ৬০০ms target।
- End-of-utterance detection < ২০০ms।
- Interruption handling — user মাঝে বললে instant stop।
মূল উপলব্ধি: Latency UX-এর foundation — voice product-এ ১ second-এর পার্থক্য usage halve করতে পারে। Engineering-এর প্রতি millisecond মূল্যবান।
অনুশীলন
-
হিসাব করুন: ৪৪.১kHz stereo, ১৬-bit, ৩ মিনিট গান — uncompressed file size কত MB?
$44100 \times 2 \text{ channel} \times 2 \text{ byte} \times 180 \text{ sec} = 31{,}752{,}000$ byte ≈ ৩০.৩ MB।
MP3 compressed ~৩ MB। তাই neural codec (EnCodec, SoundStream) ৬-৩২ kbps-এ stunning।
-
হাতে-কলমে: torchaudio দিয়ে একটি wav লোড করে spectrogram plot করুন।
import torchaudio, matplotlib.pyplot as plt wav, sr = torchaudio.load("speech.wav") spec = torchaudio.transforms.MelSpectrogram(sr)(wav) plt.imshow(spec.log2()[0].numpy(), aspect='auto', origin='lower') plt.show() -
ভাবুন: বাংলা podcast-এ AI narrator-এর জন্য ৩টি ethical guideline লিখুন।
- Disclosure — শ্রোতাকে জানান voice AI-generated।
- Consent — voice clone হলে original speaker-এর written permission।
- Watermarking — audio file-এ inaudible AI-signature embed।
আরও পড়ুন
- পাঠ ২২ · Video generation পরবর্তী পাঠ Sora, Veo — temporal consistency-এর গভীরে।
- পাঠ ২০ · Text generation আগের পাঠ LLM sampling — audio LM-এর intuition একই।
- Computer Vision Course cross-link Spectrogram = image — visual model audio-তেও কাজ করে।
- সব AI Courses দেখুন ABCL TECH Python, ML, DL, NLP, CV, GenAI, RL, MLOps — সব AI কোর্স একসাথে।