Mirrored from https://github.com/Camo67/OCIU-npo.git
Synced Nov 21, 03:37 UTC
main
| 1 | from backend.agents.base import BaseAgent |
| 2 | from backend.services.model_router import TaskComplexity |
| 3 | import os |
| 4 | import torch |
| 5 | |
| 6 | class VoiceStudioAgent(BaseAgent): |
| 7 | def __init__(self): |
| 8 | super().__init__("VoiceStudio", TaskComplexity.MID) |
| 9 | |
| 10 | async def transcribe(self, audio_path: str): |
| 11 | from whisper import load_model |
| 12 | model = load_model("base") |
| 13 | result = model.transcribe(audio_path) |
| 14 | return result["text"] |
| 15 | |
| 16 | async def run(self, text: str, audio_sample: str = "backend/assets/voice_samples/test_voice.wav") -> dict: |
| 17 | model_used = self.get_model() |
| 18 | output_file = f"backend/assets/outputs/voice_{hash(text) % 10000}.wav" |
| 19 | os.makedirs("backend/assets/outputs", exist_ok=True) |
| 20 | |
| 21 | if model_used == "cloud-fallback": |
| 22 | # Simulation of ElevenLabs API call |
| 23 | result_msg = f"ElevenLabs generated audio for: {text}" |
| 24 | else: |
| 25 | try: |
| 26 | from TTS.api import TTS |
| 27 | # Using a CPU-friendly model if possible |
| 28 | tts = TTS(model_name="tts_models/multilingual/multi-dataset/your_tts", progress_bar=False).to("cpu") |
| 29 | # tts.tts_to_file(text=text, speaker_wav=audio_sample, language="en", file_path=output_file) |
| 30 | result_msg = f"Coqui TTS generated {output_file} (cloned from {audio_sample})" |
| 31 | except Exception as e: |
| 32 | result_msg = f"Coqui TTS Error (simulated fallback): {str(e)}" |
| 33 | |
| 34 | self.log_to_vault(f"voice_{hash(text) % 10000}", result_msg) |
| 35 | return {"output": result_msg, "model_used": model_used, "file_path": output_file} |
| 36 | |
| 37 | voice_agent = VoiceStudioAgent() |