Usagert12/voice-contrastive-demo
๐ค Voice Conversion with Contrastive Learning
Enhancement of FreeVC Using Contrastive Learning Techniques
MS Thesis Project Hassan | ITU Pakistan | Computer Science
๐ฏ About This Demo
This demo showcases the enhancement of voice conversion using contrastive learning in the speaker latent space.
Two Models Compared:
1. Baseline FreeVC
- Standard voice conversion architecture
- Speaker encoder: WavLM embeddings
- Content encoder: Information Perturbation
- Flow-based generator
2. Enhanced Contrastive Model โจ
- Incorporates contrastive learning in 256-dim speaker space
- Positive pairs (same speaker) pulled together
- Negative pairs (different speakers) pushed apart
- Result: Better speaker-content disentanglement
๐ How to Use
- Upload Source Audio - The content you want to convert (what to say)
- Upload Target Speaker - The voice identity (whose voice to use)
- Select Model(s) - Baseline, Enhanced, or Both for comparison
- Click Convert - Listen to the results!
Tips for Best Results:
- Use clear audio with minimal background noise
- Provide 5-10 seconds of target speaker audio
- Try "Both" mode to hear the improvement from contrastive learning
- Source and target can be different genders
๐ Performance Improvements
Contrastive learning demonstrates significant improvements:
๐ฌ Technical Details
Dataset
- Primary: VCTK Corpus (109 speakers, English)
- Duration filtering: Files โฅ5 seconds prioritized
- Split: 70% train, 10% validation, 20% test
Architecture
- Generator: Modified HiFi-GAN with speaker conditioning
- Discriminator: Multi-scale, multi-period
- Loss Functions:
- Standard: Generator, Discriminator, Mel-spectrogram, KL divergence
- Novel: Contrastive loss with on-the-fly pair calculation
Training
- Platform: Kaggle (Tesla P100, 16GB VRAM)
- Epochs: 960 epochs
- Steps: 326,400 steps
- Optimizer: AdamW
Key Innovation
Contrastive learning enforces better speaker-content separation by:
- Creating positive pairs: same speaker, different utterances
- Creating negative pairs: different speakers, same content
- Optimizing embeddings to maximize inter-speaker distance
- Minimizing intra-speaker variance
๐ Research Context
Problem Statement
Traditional voice conversion models struggle with speaker-content disentanglement:
- Speaker identity leaks into content representation
- Content information bleeds into speaker embeddings
- Poor generalization to unseen speakers
Solution
Explicit separation enforcement through contrastive learning in the speaker latent space, resulting in:
- Better speaker identity preservation
- Improved content quality
- Enhanced generalization
- Clearer speaker-content boundaries (validated via t-SNE)
Related Work
This research builds upon:
- FreeVC: One-Shot Voice Conversion
- Contrastive Learning in Speech Processing
- Speaker Embedding Disentanglement
๐ Academic Information
Thesis Title: Enhancement of Voice Conversion using Contrastive Learning Techniques
Student: Hassan Institution: Information Technology University (ITU), Pakistan Program: MS Computer Science Year: 2025
Advisor: [Advisor Name] Committee: [Committee Members]
๐ป Implementation
Technologies Used
- Framework: PyTorch
- UI: Gradio
- Audio Processing: librosa, soundfile
- Model Architecture: FreeVC (enhanced)
Code Structure
app.py # Entry point
demo_integrated.py # Gradio interface
model_wrapper.py # Model loading
models.py # FreeVC architecture
utils.py # Utilities๐ Links
- ๐ Thesis Paper: [Coming Soon]
- ๐ป Code Repository: [GitHub Link]
- ๐ Institution: ITU Pakistan
๐ Citation
If you use this work in your research, please cite:
@mastersthesis{hassan2025voice,
title={Enhancement of Voice Conversion using Contrastive Learning Techniques},
author={Hassan},
year={2025},
school={Information Technology University, Pakistan},
type={MS Thesis}
}โ๏ธ Technical Notes
First Load
The first time you use this demo, model loading may take 1-2 minutes. Subsequent uses will be faster.
Performance
- With GPU: ~5-10 seconds per conversion
- With CPU: ~30-60 seconds per conversion
Limitations
- Optimized for English (VCTK dataset)
- Best with clear, studio-quality audio
- May struggle with extreme cross-gender conversion
- Background noise affects quality
๐ฎ Future Work
- Extension to Urdu language voice conversion
- Integration with TTS for complete synthesis pipeline
- Real-time conversion optimization
- Multi-speaker simultaneous conversion
- Mobile deployment
๐ค Acknowledgments
- VCTK Corpus creators
- FreeVC original authors
- ITU Pakistan CS Department
- Thesis advisor and committee
- Kaggle for GPU resources
โ ๏ธ Disclaimer
This is a research prototype for academic demonstration. Audio quality may vary with different inputs. Not intended for production use without further validation.
๐ Contact
For questions or collaboration:
- Email: [Your Email]
- LinkedIn: [Your LinkedIn]
- GitHub: [Your GitHub]
Built with โค๏ธ using:
- ๐ค Gradio
- ๐ฅ PyTorch
- ๐ต librosa
- ๐ NumPy
Last Updated: December 2025
