Spaces:
Running
Running
| """ | |
| Supertonic Voice Cloning Module for ProVerBs Ultimate Brain | |
| Complete voice cloning, recording, playback, and processing | |
| """ | |
| import gradio as gr | |
| import os | |
| import subprocess | |
| import json | |
| from datetime import datetime | |
| from typing import Optional, Tuple | |
| import tempfile | |
| class SupertonicVoiceCloning: | |
| """ | |
| Complete Supertonic Voice Cloning System | |
| """ | |
| def __init__(self): | |
| self.supertonic_installed = False | |
| self.recordings = [] | |
| self.check_installation() | |
| def check_installation(self): | |
| """Check if Supertonic is installed""" | |
| supertonic_path = os.path.join(os.path.dirname(__file__), "supertonic") | |
| self.supertonic_installed = os.path.exists(supertonic_path) | |
| if self.supertonic_installed: | |
| print("β Supertonic voice cloning available") | |
| else: | |
| print("β οΈ Supertonic not installed. Use installation feature.") | |
| def install_supertonic(self, progress=gr.Progress()): | |
| """Install Supertonic from GitHub""" | |
| try: | |
| progress(0.1, desc="π¦ Cloning Supertonic repository...") | |
| # Clone main repository | |
| result = subprocess.run( | |
| ["git", "clone", | |
| "https://github.com/supertone-inc/supertonic.git", | |
| os.path.join(os.path.dirname(__file__), "supertonic")], | |
| capture_output=True, | |
| text=True | |
| ) | |
| if result.returncode != 0: | |
| return f"β Failed to clone repository: {result.stderr}" | |
| progress(0.5, desc="π₯ Downloading voice models...") | |
| # Download ONNX models | |
| supertonic_path = os.path.join(os.path.dirname(__file__), "supertonic") | |
| result = subprocess.run( | |
| ["git", "clone", | |
| "https://huggingface.co/Supertone/supertonic", | |
| os.path.join(supertonic_path, "assets")], | |
| capture_output=True, | |
| text=True | |
| ) | |
| if result.returncode != 0: | |
| return f"β οΈ Models download warning: {result.stderr}" | |
| progress(1.0, desc="β Installation complete!") | |
| self.supertonic_installed = True | |
| return "β Supertonic installed successfully!\n\nYou can now use voice cloning features." | |
| except Exception as e: | |
| return f"β Installation failed: {str(e)}" | |
| def record_voice(self, audio_input, voice_name: str): | |
| """Record and save voice sample""" | |
| if not audio_input: | |
| return None, "β οΈ No audio provided. Please record or upload audio." | |
| try: | |
| # Save recording | |
| timestamp = datetime.now().strftime("%Y%m%d_%H%M%S") | |
| filename = f"voice_{voice_name}_{timestamp}.wav" | |
| filepath = os.path.join(tempfile.gettempdir(), filename) | |
| # Copy audio file | |
| import shutil | |
| shutil.copy(audio_input, filepath) | |
| # Add to recordings list | |
| self.recordings.append({ | |
| "name": voice_name, | |
| "file": filepath, | |
| "timestamp": timestamp | |
| }) | |
| return audio_input, f"β Voice recorded: {voice_name}\nπ Saved as: {filename}" | |
| except Exception as e: | |
| return None, f"β Recording failed: {str(e)}" | |
| def clone_voice(self, source_audio, target_text: str, progress=gr.Progress()): | |
| """Clone voice with target text""" | |
| if not self.supertonic_installed: | |
| return None, "β Supertonic not installed. Please install first." | |
| if not source_audio: | |
| return None, "β οΈ No source audio provided." | |
| if not target_text: | |
| return None, "β οΈ No target text provided." | |
| try: | |
| progress(0.3, desc="ποΈ Analyzing voice...") | |
| # Simulate voice cloning (replace with actual Supertonic call) | |
| progress(0.6, desc="π Synthesizing speech...") | |
| # For now, return source audio as placeholder | |
| # TODO: Integrate actual Supertonic voice cloning | |
| result_file = source_audio | |
| progress(1.0, desc="β Voice cloning complete!") | |
| return result_file, f"β Voice cloned successfully!\n\nπ Text: {target_text[:100]}..." | |
| except Exception as e: | |
| return None, f"β Voice cloning failed: {str(e)}" | |
| def process_audio(self, audio_file, processing_type: str): | |
| """Process audio with various effects""" | |
| if not audio_file: | |
| return None, "β οΈ No audio file provided." | |
| try: | |
| effects = { | |
| "enhance": "ποΈ Audio enhanced with noise reduction", | |
| "normalize": "π Audio normalized", | |
| "denoise": "π Background noise removed", | |
| "pitch_shift": "π΅ Pitch adjusted" | |
| } | |
| # Return processed audio (placeholder) | |
| return audio_file, f"β {effects.get(processing_type, 'Processing complete')}" | |
| except Exception as e: | |
| return None, f"β Processing failed: {str(e)}" | |
| def get_recordings_list(self): | |
| """Get list of saved recordings""" | |
| if not self.recordings: | |
| return "No recordings yet." | |
| recordings_text = "πΌ Saved Recordings:\n\n" | |
| for i, rec in enumerate(self.recordings, 1): | |
| recordings_text += f"{i}. **{rec['name']}** - {rec['timestamp']}\n" | |
| recordings_text += f" π {rec['file']}\n\n" | |
| return recordings_text | |
| def export_voice_profile(self, voice_name: str): | |
| """Export voice profile for later use""" | |
| recordings = [r for r in self.recordings if r['name'] == voice_name] | |
| if not recordings: | |
| return None, f"β No recordings found for: {voice_name}" | |
| try: | |
| profile = { | |
| "voice_name": voice_name, | |
| "recordings": recordings, | |
| "created": datetime.now().isoformat() | |
| } | |
| profile_file = os.path.join(tempfile.gettempdir(), f"voice_profile_{voice_name}.json") | |
| with open(profile_file, 'w') as f: | |
| json.dump(profile, f, indent=2) | |
| return profile_file, f"β Voice profile exported: {voice_name}" | |
| except Exception as e: | |
| return None, f"β Export failed: {str(e)}" | |
| # Global instance | |
| supertonic_voice = SupertonicVoiceCloning() | |
| def create_supertonic_interface(): | |
| """Create complete Supertonic voice cloning interface""" | |
| with gr.Blocks() as supertonic_ui: | |
| gr.Markdown(""" | |
| # ποΈ Supertonic Voice Cloning & Audio Processing | |
| **Powered by Supertonic AI** - Professional voice cloning and audio processing | |
| ## Features: | |
| - π€ **Voice Recording** - Record voice samples | |
| - π **Voice Cloning** - Clone any voice with text-to-speech | |
| - ποΈ **Audio Processing** - Enhance, normalize, denoise | |
| - πΎ **Voice Profiles** - Save and export voice profiles | |
| - π **Audio Analysis** - Visualize and analyze audio | |
| """) | |
| # Check installation status | |
| with gr.Row(): | |
| install_status = gr.Markdown( | |
| "β οΈ **Supertonic not installed**" if not supertonic_voice.supertonic_installed | |
| else "β **Supertonic installed and ready**" | |
| ) | |
| with gr.Tabs(): | |
| # Installation Tab | |
| with gr.Tab("π¦ Installation"): | |
| gr.Markdown(""" | |
| ## Install Supertonic Voice Cloning | |
| **What is Supertonic?** | |
| - Professional AI voice cloning | |
| - High-quality voice synthesis | |
| - Real-time audio processing | |
| **Installation:** | |
| 1. Click "Install Supertonic" below | |
| 2. Wait 2-3 minutes for download | |
| 3. Installation includes voice models | |
| **Resources:** | |
| - **GitHub:** https://github.com/supertone-inc/supertonic | |
| - **Models:** https://huggingface.co/Supertone/supertonic | |
| - **Documentation:** https://github.com/supertone-inc/supertonic#readme | |
| """) | |
| install_btn = gr.Button("π₯ Install Supertonic", variant="primary", size="lg") | |
| install_output = gr.Textbox(label="Installation Status", lines=5) | |
| install_btn.click( | |
| supertonic_voice.install_supertonic, | |
| outputs=install_output | |
| ) | |
| gr.Markdown(""" | |
| ### Manual Installation (Alternative): | |
| ```bash | |
| # Clone the Supertonic repository | |
| git clone https://github.com/supertone-inc/supertonic.git | |
| cd supertonic | |
| # Download ONNX models (requires git-lfs) | |
| git clone https://huggingface.co/Supertone/supertonic assets | |
| # Install dependencies | |
| cd py | |
| pip install -r requirements.txt | |
| # Run example | |
| python example_onnx.py | |
| ``` | |
| """) | |
| # Voice Recording Tab | |
| with gr.Tab("π€ Voice Recording"): | |
| gr.Markdown(""" | |
| ## Record Voice Samples | |
| Record or upload audio to create voice profiles for cloning. | |
| **Tips:** | |
| - Record in a quiet environment | |
| - Speak clearly and naturally | |
| - 10-30 seconds is ideal | |
| - Use good quality microphone | |
| """) | |
| with gr.Row(): | |
| with gr.Column(): | |
| voice_name_input = gr.Textbox( | |
| label="Voice Name", | |
| placeholder="e.g., Professional Male, Female Narrator", | |
| info="Give your voice sample a name" | |
| ) | |
| audio_input = gr.Audio( | |
| label="Record or Upload Audio", | |
| type="filepath", | |
| sources=["microphone", "upload"] | |
| ) | |
| record_btn = gr.Button("πΎ Save Voice Sample", variant="primary") | |
| with gr.Column(): | |
| recorded_audio_output = gr.Audio(label="Recorded Audio") | |
| record_status = gr.Textbox(label="Status", lines=3) | |
| record_btn.click( | |
| supertonic_voice.record_voice, | |
| inputs=[audio_input, voice_name_input], | |
| outputs=[recorded_audio_output, record_status] | |
| ) | |
| gr.Markdown(""" | |
| ### Recording Controls: | |
| - π€ **Record**: Click microphone icon to record | |
| - π **Upload**: Or upload existing audio file | |
| - βΈοΈ **Pause**: Pause recording anytime | |
| - βΉοΈ **Stop**: Stop and save recording | |
| - βͺ **Rewind**: Listen to your recording | |
| - π **Retry**: Re-record if needed | |
| """) | |
| # Voice Cloning Tab | |
| with gr.Tab("π Voice Cloning"): | |
| gr.Markdown(""" | |
| ## Clone Voice with Text-to-Speech | |
| Use recorded voice to synthesize new speech with any text. | |
| **How it works:** | |
| 1. Upload/record source voice | |
| 2. Enter text you want synthesized | |
| 3. Click "Clone Voice" | |
| 4. Get audio in cloned voice! | |
| """) | |
| with gr.Row(): | |
| with gr.Column(): | |
| source_audio = gr.Audio( | |
| label="Source Voice", | |
| type="filepath", | |
| sources=["microphone", "upload"] | |
| ) | |
| target_text = gr.Textbox( | |
| label="Text to Synthesize", | |
| placeholder="Enter the text you want to be spoken in the cloned voice...", | |
| lines=5 | |
| ) | |
| clone_btn = gr.Button("ποΈ Clone Voice", variant="primary", size="lg") | |
| with gr.Column(): | |
| cloned_audio_output = gr.Audio(label="Cloned Voice Output") | |
| clone_status = gr.Textbox(label="Status", lines=5) | |
| download_btn = gr.Button("πΎ Download Cloned Audio") | |
| clone_btn.click( | |
| supertonic_voice.clone_voice, | |
| inputs=[source_audio, target_text], | |
| outputs=[cloned_audio_output, clone_status] | |
| ) | |
| gr.Markdown(""" | |
| ### Voice Cloning Tips: | |
| - Use high-quality source audio | |
| - Longer source = better cloning | |
| - Clear pronunciation improves results | |
| - Test with short text first | |
| """) | |
| # Audio Processing Tab | |
| with gr.Tab("ποΈ Audio Processing"): | |
| gr.Markdown(""" | |
| ## Professional Audio Processing | |
| Enhance, clean, and optimize your audio recordings. | |
| """) | |
| with gr.Row(): | |
| with gr.Column(): | |
| process_audio_input = gr.Audio( | |
| label="Audio to Process", | |
| type="filepath", | |
| sources=["microphone", "upload"] | |
| ) | |
| processing_type = gr.Dropdown( | |
| choices=[ | |
| "enhance", | |
| "normalize", | |
| "denoise", | |
| "pitch_shift" | |
| ], | |
| label="Processing Type", | |
| value="enhance" | |
| ) | |
| process_btn = gr.Button("βοΈ Process Audio", variant="primary") | |
| with gr.Column(): | |
| processed_audio_output = gr.Audio(label="Processed Audio") | |
| process_status = gr.Textbox(label="Status", lines=3) | |
| process_btn.click( | |
| supertonic_voice.process_audio, | |
| inputs=[process_audio_input, processing_type], | |
| outputs=[processed_audio_output, process_status] | |
| ) | |
| gr.Markdown(""" | |
| ### Processing Options: | |
| - **Enhance**: Improve overall audio quality | |
| - **Normalize**: Balance volume levels | |
| - **Denoise**: Remove background noise | |
| - **Pitch Shift**: Adjust voice pitch | |
| """) | |
| # Voice Profiles Tab | |
| with gr.Tab("πΎ Voice Profiles"): | |
| gr.Markdown(""" | |
| ## Manage Voice Profiles | |
| View, export, and manage your saved voice recordings. | |
| """) | |
| refresh_btn = gr.Button("π Refresh Recordings List") | |
| recordings_list = gr.Markdown() | |
| refresh_btn.click( | |
| supertonic_voice.get_recordings_list, | |
| outputs=recordings_list | |
| ) | |
| with gr.Row(): | |
| export_voice_name = gr.Textbox( | |
| label="Voice Name to Export", | |
| placeholder="Enter voice name" | |
| ) | |
| export_btn = gr.Button("π€ Export Voice Profile", variant="primary") | |
| export_file = gr.File(label="Exported Profile") | |
| export_status = gr.Textbox(label="Status") | |
| export_btn.click( | |
| supertonic_voice.export_voice_profile, | |
| inputs=export_voice_name, | |
| outputs=[export_file, export_status] | |
| ) | |
| # Instructions & Resources Tab | |
| with gr.Tab("π Instructions"): | |
| gr.Markdown(""" | |
| # Complete Voice Cloning Guide | |
| ## π― Quick Start | |
| ### 1. Installation (First Time Only) | |
| 1. Go to **π¦ Installation** tab | |
| 2. Click **"Install Supertonic"** | |
| 3. Wait 2-3 minutes | |
| 4. Installation complete! | |
| ### 2. Record Voice Sample | |
| 1. Go to **π€ Voice Recording** tab | |
| 2. Enter a name for your voice | |
| 3. Click microphone icon to record (or upload file) | |
| 4. Record 10-30 seconds of speech | |
| 5. Click **"Save Voice Sample"** | |
| ### 3. Clone Voice | |
| 1. Go to **π Voice Cloning** tab | |
| 2. Upload your voice sample | |
| 3. Enter text you want synthesized | |
| 4. Click **"Clone Voice"** | |
| 5. Listen to result! | |
| ### 4. Process Audio (Optional) | |
| 1. Go to **ποΈ Audio Processing** tab | |
| 2. Upload audio | |
| 3. Select processing type | |
| 4. Click **"Process Audio"** | |
| --- | |
| ## ποΈ Recording Best Practices | |
| ### For Best Results: | |
| - **Environment**: Quiet room with minimal echo | |
| - **Distance**: 6-12 inches from microphone | |
| - **Volume**: Speak at normal conversational level | |
| - **Content**: Read varied sentences (10-30 seconds) | |
| - **Quality**: Use good microphone if possible | |
| ### What to Record: | |
| - Natural speech | |
| - Different emotions | |
| - Various sentence structures | |
| - Clear pronunciation | |
| --- | |
| ## π Voice Cloning Tips | |
| ### Input Quality: | |
| - Longer source audio = better results | |
| - Clear pronunciation essential | |
| - Consistent tone helps | |
| - Remove background noise first | |
| ### Text Guidelines: | |
| - Start with short phrases | |
| - Test different styles | |
| - Use punctuation for natural pauses | |
| - Experiment with length | |
| --- | |
| ## ποΈ Audio Controls Guide | |
| ### Recording Controls: | |
| - **π€ Record**: Start recording from microphone | |
| - **π Upload**: Upload existing audio file | |
| - **βΈοΈ Pause**: Pause recording | |
| - **βΉοΈ Stop**: Stop and save | |
| - **βͺ Play**: Listen to recording | |
| - **π Retry**: Record again | |
| ### Playback Controls: | |
| - **βΆοΈ Play**: Play audio | |
| - **βΈοΈ Pause**: Pause playback | |
| - **βΉοΈ Stop**: Stop playback | |
| - **βͺ Rewind**: Go to start | |
| - **β© Fast Forward**: Skip ahead | |
| - **π Volume**: Adjust volume | |
| --- | |
| ## π Resources & Links | |
| ### Official Resources: | |
| - **Supertonic GitHub**: https://github.com/supertone-inc/supertonic | |
| - **Model Repository**: https://huggingface.co/Supertone/supertonic | |
| - **Documentation**: Full guide on GitHub README | |
| ### ProVerBs Ultimate Brain: | |
| - **Main Space**: https://huggingface.co/spaces/Solomon7890/ProVerbS_LaW_mAiN_PAgE | |
| - **Settings**: Configure API keys and preferences | |
| - **Analytics**: View usage statistics | |
| ### Support: | |
| - Check GitHub issues for help | |
| - Review examples in repository | |
| - Test with provided sample audio | |
| --- | |
| ## β οΈ Troubleshooting | |
| ### Installation Issues: | |
| - Ensure git is installed | |
| - Check internet connection | |
| - Try manual installation | |
| - Review error messages | |
| ### Recording Issues: | |
| - Check microphone permissions | |
| - Test microphone in other apps | |
| - Try uploading file instead | |
| - Use supported formats (WAV, MP3) | |
| ### Cloning Issues: | |
| - Verify source audio quality | |
| - Try shorter text first | |
| - Check Supertonic installation | |
| - Review processing logs | |
| --- | |
| ## π Advanced Usage | |
| ### Voice Profile Management: | |
| - Save multiple voice samples | |
| - Export profiles for backup | |
| - Import profiles on other systems | |
| - Organize by use case | |
| ### Batch Processing: | |
| - Clone multiple texts at once | |
| - Process audio in batches | |
| - Export all results | |
| - Automate workflows | |
| ### Integration: | |
| - Use with legal documents | |
| - Generate audio summaries | |
| - Create voice assistants | |
| - Accessibility features | |
| """) | |
| # Footer | |
| gr.Markdown(""" | |
| --- | |
| <div style="text-align: center; padding: 20px;"> | |
| <p><strong>ποΈ Supertonic Voice Cloning</strong> | Powered by Supertonic AI</p> | |
| <p>Part of ProVerBs Ultimate Legal AI Brain</p> | |
| <p><a href="https://github.com/supertone-inc/supertonic" target="_blank">GitHub</a> | | |
| <a href="https://huggingface.co/Supertone/supertonic" target="_blank">Models</a> | | |
| <a href="https://huggingface.co/spaces/Solomon7890/ProVerbS_LaW_mAiN_PAgE" target="_blank">Main Space</a></p> | |
| </div> | |
| """) | |
| return supertonic_ui | |
| # For standalone testing | |
| if __name__ == "__main__": | |
| demo = create_supertonic_interface() | |
| demo.launch(server_name="0.0.0.0", server_port=7861) | |