CoolFace
Apppublic

Usagert12/voice-contrastive-demo

sourceHugging Facemitupdated 10mo agoView on Hugging Face
0likes
App README

๐ŸŽค 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

  1. 1.Upload Source Audio - The content you want to convert (what to say)
  2. 2.Upload Target Speaker - The voice identity (whose voice to use)
  3. 3.Select Model(s) - Baseline, Enhanced, or Both for comparison
  4. 4.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:

MetricBaselineEnhancedImprovement
F0 Correlation0.780.89+14%
Speaker Similarity0.850.94+11%
Mel Distance3.2 dB2.1 dB-34%

๐Ÿ”ฌ 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:

  1. 1.Creating positive pairs: same speaker, different utterances
  2. 2.Creating negative pairs: different speakers, same content
  3. 3.Optimizing embeddings to maximize inter-speaker distance
  4. 4.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:

bibtex
@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