Spaces:
Paused
Paused
| import requests | |
| import base64 | |
| # ===================== CONFIG ===================== | |
| BASE_URL = "https://michsethowusu-kasanoma-api.hf.space" | |
| API_KEY = "kasanoma" # Your Space's API key | |
| # ================================================== | |
| # Auth for HTTP Basic (username: piper, password: API_KEY) | |
| auth = ("piper", API_KEY) if API_KEY else None | |
| # Long sample Twi sentences | |
| sentences = [ | |
| "Mede awɔ yi, ɛyɛ me anigyeɛ sɛ mɛka me ho asɛm kyerɛ wo. Wɔ afe apem aha-nkron ne aduonu nnan mu no, na yɛde asomdwoeɛ aba ha, nanso nnipa pii da so ara taa yɛ adwuma den na wɔn ani nnye nkɔsoɔ ho.", | |
| "Sɛ wopɛ sɛ wosua adeɛ a, ɛsɛ sɛ wotie nyansa ne afotu a wɔn a wɔadi kan no de ma wo. Me nananom kyerɛɛ me sɛ ɔkwan a ɛyɛ den no, ɛno na ɛma nkɔsoɔ ba, efisɛ ɔkwan a ɛyɛ mmerɛw no taa de ɔhaw ba akyiri yi.", | |
| "Nnwoma akenkan yɛ adeɛ a ɛho hia paa. Ɛma yɛnya nimdeɛ foforɔ, na ɛma yɛn adwene mu da hɔ. Sɛ wokenkan nnwoma a, wubehu sɛ w’ani bɛtumi ahu nsɛm a ɛrekɔ so wɔ wiase afa nyinaa, na woatumi asi gyinaeɛ papa bi wɔ w’asetena mu.", | |
| "Abɔdeɛ a ɛwɔ yɛn atwa yɛn ho ahyia no ho hia yie. Ɛsɛ sɛ yɛhwɛ nsuo, mframa ne kwaeɛ yie na yɛatumi anya apɔmuden ne ahotɔ. Sɛ yɛnsɛe abɔdeɛ a, ɛno bɛsɛe yɛn ankasa asetena wɔ daakye, na ɛno nti, ɛsɛ sɛ obiara boa ma wɔbɔ abɔdeɛ ho ban.", | |
| "Sɛ wohwɛ abakɔsɛm mu a, wubehu sɛ Ghanafoɔ yɛ nnipa a wɔn ani gye amammerɛ ne wɔn kwan a wɔfa so di wɔn asetena ho. Yɛwɔ aduane ahodoɔ, nnwom ne asa a ɛda nso, na ɛyɛ ahomasoɔ sɛ wobɛtumi akora saa agyapadeɛ yi so ama awoɔ ntoatoasoɔ a ɛbɛba no." | |
| ] | |
| for idx, text in enumerate(sentences, start=1): | |
| print(f"\nProcessing sentence {idx}...") | |
| payload = { | |
| "text": text, | |
| "local": "twi_GH", | |
| "voice": "kofi-medium", | |
| "silence": 1, | |
| "speed": 1.0, | |
| "lite_file": True | |
| } | |
| # Send synthesis request with auth | |
| resp = requests.post( | |
| f"{BASE_URL}/api/v1/synthesize", | |
| json=payload, | |
| auth=auth | |
| ) | |
| if resp.status_code != 200: | |
| print(f"Error synthesising sentence {idx}: {resp.status_code} {resp.text}") | |
| continue | |
| data = resp.json() | |
| audio_b64 = data.get("audio_base64") | |
| if not audio_b64: | |
| print(f"No audio_base64 in response") | |
| continue | |
| # Decode the base64 audio and save to file | |
| audio_bytes = base64.b64decode(audio_b64) | |
| out_name = f"output_twi_{idx}.wav" | |
| with open(out_name, "wb") as f: | |
| f.write(audio_bytes) | |
| print(f" Saved as {out_name}") | |
| print("\nAll done! Check your current folder for the .wav files.") | |