Untitled
unknown
plain_text
a year ago
1.5 kB
3
Indexable
async def generate_audio(script: str):
cleaned_script = script.replace('*', '').replace('\\n', '').replace('\n', '').replace('Locutor:', '').replace('Locutora:', '')
# Cliente de Text to Speech
client = texttospeech.TextToSpeechClient()
input_text = texttospeech.SynthesisInput(text=cleaned_script)
voice = texttospeech.VoiceSelectionParams(
language_code="es-ES",
name="es-ES-Wavenet-B",
)
audio_config = texttospeech.AudioConfig(
audio_encoding=texttospeech.AudioEncoding.MP3
)
response = client.synthesize_speech(
request={"input": input_text, "voice": voice, "audio_config": audio_config}
)
# Genera un nombre de archivo único usando UUID
file_name = f"{uuid.uuid4()}.mp3"
bucket_name = "your-bucket-name" # Reemplazar con el nombre de tu bucket
# Cliente de Google Cloud Storage
storage_client = storage.Client()
bucket = storage_client.bucket(bucket_name)
blob = bucket.blob(file_name)
# Subir el contenido del audio al bucket
blob.upload_from_string(
response.audio_content,
content_type="audio/mp3"
)
print(f'Audio content uploaded to GCP bucket "{bucket_name}" with file name "{file_name}"')
# Construir la URI de gsutil
gsutil_uri = f"gs://{bucket_name}/{file_name}"
return {
"message": "Audio generated and uploaded successfully!",
"bucket": bucket_name,
"file_name": file_name,
"gsutil_uri": gsutil_uri
}Editor is loading...
Leave a Comment