Lesson 138 — Advanced

Audio: Speech to Text & Text to Speech

Speech-to-text aur text-to-speech dono hi production mein roz chalte hain — call transcriptions, captions, voice replies, IVR. Is lesson mein hum dekhenge STT model se actually kya milta hai (transcript + timestamps + confidence), batch vs streaming, diarization, WER ko kaise padhna hai, aur TTS mein voice, prosody, pronunciation aur streaming synthesis — hosted vs local ke trade-off ke saath.

⏱ 20 min• Advanced• Audio: How Sound Becomes Tokens

STT se kya milta hai — transcript is not prose

Kya hai?

STT model (jaise Whisper-family) audio deta hai toh output clean edited prose nahi hota — transcript hota hai: words, optional word-level timestamps, segments, aur kabhi kabhi confidence signals. Punctuation aur casing bhi model-dependent.

Kab kaam aata hai?

Meeting notes, call analytics, captions, voice-command parsing, aur RAG ke liye audio corpus ka text conversion. Har jagah jahan "sun kar likhna" ka kaam hai.

Kahan milta hai?

Hosted speech APIs mein, open speech models (Whisper jaise) ko locally GPU pe chala kar, aur realtime transcription services mein.

# STT output ka typical shape — transcript + segments + timestamps
result = stt.transcribe("meeting.mp3", word_timestamps=True)

print(result.text)                    # ek blob: transcript
for seg in result.segments:            # time ranges ke saath segments
    print(round(seg.start, 1), "-", round(seg.end, 1), seg.text)
# segments ko downstream use karte hain: search, speaker join, highlights
Expectation set karo: Transcript mein filler words, galat punctuation aur kabhi-kabhi dropped words aate hain. Usse "record" mat maano — ek noisy measurement maano, jise downstream validation se guzarna padta hai.

Batch vs streaming transcription

# Streaming transcription — partial aur final hypotheses alag handle karo
for event in stt.stream(mic):
    if event.type == "partial":
        ui.show_live(event.text)        # user ko dikhaao, store mat karo
    elif event.type == "final":
        transcript.append(event)        # yahi asli record hai
        agent_pipeline.feed(event)      # downstream processing
Decision rule: Accuracy chahiye aur wait kar sakte ho → batch. Live captions ya barge-in wala voice agent → streaming, aur partial text ko kabhi final mat maano.

Diarization aur WER

# Diarization ek ALAG step hai — kaun bol raha hai, ye STT nahi batata
text = stt.transcribe("call.mp3")
segments = diarizer.run("call.mp3")    # speaker A / speaker B ranges
merged = align(text, segments)          # "kaun kab bola" ka final record

# WER (word error rate) — transcription ka quality score
# WER = (substitutions + deletions + insertions) / total reference words
# 0.1 = 10% words galat — downstream task ke hisaab se acceptable ya nahi
Vocabulary hints: Domain terms (product names, medical jargon, acronyms) prompt/custom-vocabulary ke through bolo — model phonetic guess se unhe behtar likhta hai. Ye Hinglish/accented setups mein sabse sasta improvement hai.

TTS — voice, prosody aur pronunciation

# TTS: text -> sampled audio in a chosen voice
audio = tts.synthesize(
    text="Your order total is 1,240 rupees. UPI ID: sales@shop",
    voice="female-a",          # provider ki voice list se
    speed=1.0,
)

# Pronunciation control: tricky words pehle se theek karo
text = text.replace("UPI", "U-P-I")            # acronyms spelled out
text = text.replace("1,240", "twelve forty")   # numbers bhi!
Latency chain: TTS ke saath bhi streaming hi latency bachaata hai: LLM ke tokens aate jaate hain, aur sentences bante hi audio chalti rehti hai. Full-utterance synthesis tabhi karo jab text chhota ho ya quality ka saf excuse ho.

Hosted vs local speech models

Practical combo: ek modality ke liye ek hi provider mat pakdo — STT local, TTS hosted, ya ulta, depending on quality bar aur privacy. Har pipeline ke liye apna eval set rakho: 20-30 apni recordings (accents, noise, jargon ke saath) jo har candidate pe chalti hain.

Eval first: Vendor demo clips hamesha acchi lagti hain. Asli comparison apne audio pe: apne accents, apne jargon, apni noise ke saath. WER, latency aur cost teeno table mein daalo, phir decide karo.

Exercise

Question: STT ke saath aane wale time-ranges wale segments kis kaam ke liye use hote hain — search ke liye ya file rename ke liye?

Question: Transcription quality ka standard metric jisme substitutions/deletions/insertions ginte hain, uske teen akshar kya hain?

Question: Speaker identification (kaun bol raha hai) STT karta hai ya ek alag step — diarization?

Question: TTS mein pace, pauses aur emphasis jise control karte hain, usko kya kehte hain?

Common mistakes

Desi example: Ghar ka voice note vs studio dubbing

Ghar ke voice note mein sab alag-alag hain — pehle koi likhega (STT), phir koi bole "yehan Ramesh bola tha" (diarization), aur garbad ho toh dobara record (retry). Studio dubbing (TTS) mein bhi ek word galat bola toh poora take repeat — numbers aur names sabse zyada gadbad wahi hote hain:

text
recording -> likhne wala (STT) -> speaker tag (diarizer) -> notes
text -> bolne wala (TTS) -> audio
         numbers/names pehle spell-out karo, warna garbad
Interview angle — yahan se sawaal aate hain
  • Q: STT ka output kya hota hai? — Transcript + segments + timestamps (+ confidence), edited prose nahi.
  • Q: Batch aur streaming transcription ka trade-off? — Batch: best accuracy, wait. Streaming: live, par partial revisions aur limited context.
  • Q: Diarization kyun alag step hai? — Speaker attribution ek alag problem hai jo audio analysis se aati hai, STT text se nahi; alignment bhi fail hota hai.
  • Q: WER ko kaise use karte ho? — Quality score (errors/words), par overall se zyada important hai ki errors kahan hain — task ke hisaab se threshold.
Lesson complete?

STT/TTS pipelines clear — transcript ki reality, diarization, WER, voice aur pronunciation control sab aa gaya. Agla lesson — Audio: Realtime Voice Agents — mein inhe ek live conversation loop mein jodenge, jahan latency hi design constraint hai.

Popular courses: Data Science Course in Lucknow · AI Course in Lucknow · Python Course in Lucknow · Power BI Course · Data Analytics Course