```python from audio_processing import AudioRecorder from accent_conversion import AccentConverter from whisper_integration import WhisperTranscriber import os import time def main(): # Initialize components recorder = AudioRecorder() converter = AccentConverter() transcriber = WhisperTranscriber(model_size="base") print("Accentify - Real-Time Accent Conversion System") print("Available accents: american, british, australian, indian") try: while True: print("\nMenu:") print("1. Record and transcribe") print("2. Convert accent of existing audio") print("3. Exit") choice = input("Enter your choice (1-3): ") if choice == "1": # Record audio output_file = recorder.record_and_save(duration=5) # Detect language/transcribe with Whisper print("\nTranscribing with Whisper...") whisper_result = transcriber.transcribe_audio(output_file) print(f"Detected language: {whisper_result['language']}") print(f"Transcription: {whisper_result['text']}") # Convert accent target_accent = input("Enter target accent (american/british/australian/indian): ").lower() if target_accent not in converter.models: print("Invalid accent. Using 'american' as default.") target_accent = "american" output_audio, converted_text = converter.convert_accent( output_file, source_accent="american", # In real app, detect source accent target_accent=target_accent ) print(f"\nConverted text: {converted_text}") print(f"Saved converted audio to: {output_audio}") elif choice == "2": audio_path = input("Enter path to audio file: ") if not os.path.exists(audio_path): print("File not found!") continue # First detect source accent print("Detecting source accent...") source_accent = converter.detect_accent(audio_path) print(f"Detected accent: {source_accent}") target_accent = input("Enter target accent (american/british/australian/indian): ").lower() if target_accent not in converter.models: print("Invalid accent. Using 'american' as default.") target_accent = "american" output_audio, converted_text = converter.convert_accent( audio_path, source_accent=source_accent, target_accent=target_accent ) print(f"\nConverted text: {converted_text}") print(f"Saved converted audio to: {output_audio}") elif choice == "3": print("Exiting...") break else: print("Invalid choice. Please try again.") except KeyboardInterrupt: print("\nExiting...") if __name__ == "__main__": main() ``` These Python files provide the backend functionality needed for the accent conversion system: 1. `audio_processing.py` - Handles audio recording using sounddevice 2. `accent_conversion.py` - Uses wav2vec2 for speech recognition and gTTS for text-to-speech 3. `whisper_integration.py` - Provides Whisper AI transcription capabilities 4. `requirements.txt` - Lists all required Python packages 5. `main.py` - Demonstrates the complete workflow The system can: - Record audio using the microphone - Transcribe speech using Whisper or wav2vec2 - Convert text to speech with different accents using gTTS - Save audio files and manage temporary files - Handle different input/output formats To use these files, users should: 1. Install the requirements: `pip install -r requirements.txt` 2. Run the main script: `python main.py` 3. Follow the interactive menu to record and convert speech Note: For production use, you would need to: - Handle API keys securely - Add error handling - Optimize model loading - Add web server integration (FastAPI/Flask) - Implement proper accent detection - Add more sophisticated accent conversion techniques ___METADATA_START___ {"repoId":"sakshigpatil/accentify-the-global-tongue-twister","isNew":false,"userName":"sakshigpatil"} ___METADATA_END___