Spaces:
Sleeping
Sleeping
| import os | |
| from typing import List | |
| import replicate | |
| from dotenv import load_dotenv | |
| load_dotenv() | |
| replicate_client = replicate.Client(api_token= os.getenv("REPLICATE_API_KEY")) | |
| def audio_generation( | |
| scripts: str, | |
| voice_id: str, | |
| speed: float, | |
| volume: float, | |
| pitch: int, | |
| emotion: str | |
| ): | |
| output = replicate_client.run( | |
| "minimax/speech-02-turbo", | |
| input={ | |
| "text": f"""{scripts}""", | |
| "pitch": pitch, | |
| "speed": speed, | |
| "volume": volume, | |
| "bitrate": 128000, | |
| "channel": "mono", | |
| "emotion": emotion, | |
| "voice_id": voice_id, | |
| "sample_rate": 32000, | |
| "language_boost": "English", | |
| "english_normalization": True | |
| } | |
| ) | |
| urls: List[str] = [] | |
| if isinstance(output, list) and output: | |
| first = output[0] | |
| url = getattr(first, "url", str(first)) | |
| urls = [url] | |
| elif isinstance(output, str): | |
| urls = [output] | |
| elif hasattr(output, "url"): | |
| urls = [getattr(output, "url")] | |
| if urls: | |
| return urls[0] |