Speech recognition and audio generation

Hugging Face के साथ मल्टी-मोडल मॉडल्स

James Chapman

Curriculum Manager, DataCamp

Speech

 

स्पीच वेवफॉर्म के मुख्य घटक क्या हैं?

  • Pitch: औसत फ़्रीक्वेंसी—पुरुष 85–180Hz, महिलाएँ 165–255Hz
  • Stress: भाषा, ऐक्सेंट और इमोशन पर निर्भर
  • Rhythm: संदर्भ, इमोशन और भाषा से प्रभावित

 

सोशल मीडिया पोस्ट

Hugging Face के साथ मल्टी-मोडल मॉडल्स

Automatic speech recognition

ऑडियो एन्कोड होता है, फिर ऑडियो या टेक्स्ट में डिकोड होता है.

  • टेक्स्ट और ऑडियो, दोनों sequential होते हैं
  • उदाहरण: transcription, translation, text-to-speech
Hugging Face के साथ मल्टी-मोडल मॉडल्स

Automatic speech recognition

  • Tiny मॉडल: 39M parameters, 150MB मॉडल साइज
  • Training डेटा: 680k घंटे (labeled)
from transformers import WhisperProcessor, WhisperForConditionalGeneration
processor = WhisperProcessor.from_pretrained("openai/whisper-tiny")
model = WhisperForConditionalGeneration.from_pretrained("openai/whisper-tiny")
1 https://github.com/openai/whisper
Hugging Face के साथ मल्टी-मोडल मॉडल्स

Automatic speech recognition

from datasets import load_dataset, Audio
dataset = load_dataset("CSTR-Edinburgh/vctk")["train"]
dataset = dataset.cast_column("audio", Audio(sampling_rate=16_000))

sample = dataset[0]["audio"]
input_preprocessed = processor(sample["array"], sampling_rate=sample["sampling_rate"], return_tensors="pt")
predicted_ids = model.generate(input_preprocessed.input_features)
transcription = processor.batch_decode(predicted_ids, skip_special_tokens=True) print(transcription)
['Please cool Stella.']
Hugging Face के साथ मल्टी-मोडल मॉडल्स

Audio generation

ऑडियो जनरेट करने के तीन घटक:

  • Preprocessor: resampling और feature extraction
  • Model: feature transformation
  • Vocoder: ऑडियो वेवफॉर्म के लिए अलग जनरेटिव मॉडल
from transformers import SpeechT5Processor, SpeechT5ForSpeechToSpeech, SpeechT5HifiGan

processor = SpeechT5Processor.from_pretrained("microsoft/speecht5_vc") model = SpeechT5ForSpeechToSpeech.from_pretrained("microsoft/speecht5_vc") vocoder = SpeechT5HifiGan.from_pretrained("microsoft/speecht5_hifigan")
Hugging Face के साथ मल्टी-मोडल मॉडल्स

Speech embeddings

स्पीच एम्बेडिंग स्पीच जेनरेशन पाइपलाइन में कैसे फिट होती है, इसका डायग्राम

Hugging Face के साथ मल्टी-मोडल मॉडल्स

Generating speaker embeddings

  • Pre-trained encoder: audio waveform array → encoded array (आमतौर पर 512 dimensions)
from speechbrain.inference.speaker import EncoderClassifier
speaker_model = EncoderClassifier.from_hparams(source="speechbrain/spkrec-xvect-voxceleb")
speaker_embeddings = speaker_model.encode_batch(torch.tensor(dataset[0]["audio"]["array"]))

speaker_embeddings = torch.nn.functional.normalize(speaker_embeddings, dim=2).unsqueeze(0)
Hugging Face के साथ मल्टी-मोडल मॉडल्स

Audio generation

inputs = processor(audio=dataset[0]["audio"], 
                   sampling_rate=dataset[0]["audio"]["sampling_rate"], 
                   return_tensors="pt")


speech = model.generate_speech(inputs["input_values"], speaker_embedding, vocoder=vocoder)

पहले और बाद का स्पेक्ट्रोग्राम

Hugging Face के साथ मल्टी-मोडल मॉडल्स

अभ्यास करते हैं!

Hugging Face के साथ मल्टी-मोडल मॉडल्स

Preparing Video For Download...