from flask import Flask, send_file, request from flask_cors import CORS from fairseq.checkpoint_utils import load_model_ensemble_and_task_from_hf_hub from fairseq.models.text_to_speech.hub_interface import TTSHubInterface import IPython.display as ipd app = Flask(__name__) CORS(app) models, cfg, task = load_model_ensemble_and_task_from_hf_hub( "facebook/tts_transformer-es-css10", arg_overrides={"vocoder": "hifigan", "fp16": False} ) model = models[0] TTSHubInterface.update_cfg_with_data_cfg(cfg, task.data_cfg) generator = task.build_generator([model], cfg) @app.route("/") def get_audio(): user = request.args.get('name') text = f"Hola {user}, si estás leyendo este mail es porque desde buenosaires consideramos que eres una de esas personas visionarias, capaces de mirar más allá, por eso queremos compartir contigo un hallazgo que puede cambiar el futuro de las enfermedades degenerativas." sample = TTSHubInterface.get_model_input(task, text) wav, rate = TTSHubInterface.get_prediction(task, model, generator, sample) print(f"Duration: {len(wav) / rate:.2f} seconds") print(f"Text: {text}") sound = ipd.Audio(wav, rate=rate) with open("../../audio_file.wav", "wb") as file: file.write(sound.data) return send_file("../../audio_file.wav", mimetype="audio/wav") if __name__ == "__main__": app.run(port=7860, debug=True)