Skip to content
TheChatArchiveThe Chat Archive
o1-preview-2024-09-12· OpenAIAi2 WildChat-4.8M (AI2)

Help me connect this API to my website using Flask: 1. Install the python client (docs)…

  1. User

    Help me connect this API to my website using Flask:

    1. Install the python client (docs) if you don't already have it installed.

    copy $ pip install gradio_client 2. Find the API endpoint below corresponding to your desired function in the app. Copy the code snippet, replacing the placeholder values with your own input data. If this is a private Space, you may need to pass your Hugging Face token as well (read more). Or use the API Recorder

    to automatically generate your API requests.

    api_name: /predict copy from gradio_client import Client

    client = Client("innoai/Edge-TTS-Text-to-Speech") result = client.predict( text="Hello!!", voice="", rate=0, pitch=0, api_name="/predict" ) print(result) Accepts 4 parameters: text str Required

    The input value that is provided in the "Input Text" Textbox component.

    voice Literal['', 'af-ZA-AdriNeural - af-ZA (Female)', 'af-ZA-WillemNeural - af-ZA (Male)', 'sq-AL-AnilaNeural - sq-AL (Female)', 'sq-AL-IlirNeural - sq-AL (Male)', 'am-ET-AmehaNeural - am-ET (Male)', 'am-ET-MekdesNeural - am-ET (Female)', 'ar-DZ-AminaNeural - ar-DZ (Female)', 'ar-DZ-IsmaelNeural - ar-DZ (Male)', 'ar-BH-AliNeural - ar-BH (Male)', 'ar-BH-LailaNeural - ar-BH (Female)', 'ar-EG-SalmaNeural - ar-EG (Female)', 'ar-EG-ShakirNeural - ar-EG (Male)', 'ar-IQ-BasselNeural - ar-IQ (Male)', 'ar-IQ-RanaNeural - ar-IQ (Female)', 'ar-JO-SanaNeural - ar-JO (Female)', 'ar-JO-TaimNeural - ar-JO (Male)', 'ar-KW-FahedNeural - ar-KW (Male)', 'ar-KW-NouraNeural - ar-KW (Female)', 'ar-LB-LaylaNeural - ar-LB (Female)', 'ar-LB-RamiNeural - ar-LB (Male)', 'ar-LY-ImanNeural - ar-LY (Female)', 'ar-LY-OmarNeural - ar-LY (Male)', 'ar-MA-JamalNeural - ar-MA (Male)', 'ar-MA-MounaNeural - ar-MA (Female)', 'ar-OM-AbdullahNeural - ar-OM (Male)', 'ar-OM-AyshaNeural - ar-OM (Female)', 'ar-QA-AmalNeural - ar-QA (Female)', 'ar-QA-MoazNeural - ar-QA (Male)', 'ar-SA-HamedNeural - ar-SA (Male)', 'ar-SA-ZariyahNeural - ar-SA (Female)', 'ar-SY-AmanyNeural - ar-SY (Female)', 'ar-SY-LaithNeural - ar-SY (Male)', 'ar-TN-HediNeural - ar-TN (Male)', 'ar-TN-ReemNeural - ar-TN (Female)', 'ar-AE-FatimaNeural - ar-AE (Female)', 'ar-AE-HamdanNeural - ar-AE (Male)', 'ar-YE-MaryamNeural - ar-YE (Female)', 'ar-YE-SalehNeural - ar-YE (Male)', 'az-AZ-BabekNeural - az-AZ (Male)', 'az-AZ-BanuNeural - az-AZ (Female)', 'bn-BD-NabanitaNeural - bn-BD (Female)', 'bn-BD-PradeepNeural - bn-BD (Male)', 'bn-IN-BashkarNeural - bn-IN (Male)', 'bn-IN-TanishaaNeural - bn-IN (Female)', 'bs-BA-GoranNeural - bs-BA (Male)', 'bs-BA-VesnaNeural - bs-BA (Female)', 'bg-BG-BorislavNeural - bg-BG (Male)', 'bg-BG-KalinaNeural - bg-BG (Female)', 'my-MM-NilarNeural - my-MM (Female)', 'my-MM-ThihaNeural - my-MM (Male)', 'ca-ES-EnricNeural - ca-ES (Male)', 'ca-ES-JoanaNeural - ca-ES (Female)', 'zh-HK-HiuGaaiNeural - zh-HK (Female)', 'zh-HK-HiuMaanNeural - zh-HK (Female)', 'zh-HK-WanLungNeural - zh-HK (Male)', 'zh-CN-XiaoxiaoNeural - zh-CN (Female)', 'zh-CN-XiaoyiNeural - zh-CN (Female)', 'zh-CN-YunjianNeural - zh-CN (Male)', 'zh-CN-YunxiNeural - zh-CN (Male)', 'zh-CN-YunxiaNeural - zh-CN (Male)', 'zh-CN-YunyangNeural - zh-CN (Male)', 'zh-CN-liaoning-XiaobeiNeural - zh-CN-liaoning (Female)', 'zh-TW-HsiaoChenNeural - zh-TW (Female)', 'zh-TW-YunJheNeural - zh-TW (Male)', 'zh-TW-HsiaoYuNeural - zh-TW (Female)', 'zh-CN-shaanxi-XiaoniNeural - zh-CN-shaanxi (Female)', 'hr-HR-GabrijelaNeural - hr-HR (Female)', 'hr-HR-SreckoNeural - hr-HR (Male)', 'cs-CZ-AntoninNeural - cs-CZ (Male)', 'cs-CZ-VlastaNeural - cs-CZ (Female)', 'da-DK-ChristelNeural - da-DK (Female)', 'da-DK-JeppeNeural - da-DK (Male)', 'nl-BE-ArnaudNeural - nl-BE (Male)', 'nl-BE-DenaNeural - nl-BE (Female)', 'nl-NL-ColetteNeural - nl-NL (Female)', 'nl-NL-FennaNeural - nl-NL (Female)', 'nl-NL-MaartenNeural - nl-NL (Male)', 'en-AU-NatashaNeural - en-AU (Female)', 'en-AU-WilliamNeural - en-AU (Male)', 'en-CA-ClaraNeural - en-CA (Female)', 'en-CA-LiamNeural - en-CA (Male)', 'en-HK-SamNeural - en-HK (Male)', 'en-HK-YanNeural - en-HK (Female)', 'en-IN-NeerjaExpressiveNeural - en-IN (Female)', 'en-IN-NeerjaNeural - en-IN (Female)', 'en-IN-PrabhatNeural - en-IN (Male)', 'en-IE-ConnorNeural - en-IE (Male)', 'en-IE-EmilyNeural - en-IE (Female)', 'en-KE-AsiliaNeural - en-KE (Female)', 'en-KE-ChilembaNeural - en-KE (Male)', 'en-NZ-MitchellNeural - en-NZ (Male)', 'en-NZ-MollyNeural - en-NZ (Female)', 'en-NG-AbeoNeural - en-NG (Male)', 'en-NG-EzinneNeural - en-NG (Female)', 'en-PH-JamesNeural - en-PH (Male)', 'en-PH-RosaNeural - en-PH (Female)', 'en-SG-LunaNeural - en-SG (Female)', 'en-SG-WayneNeural - en-SG (Male)', 'en-ZA-LeahNeural - en-ZA (Female)', 'en-ZA-LukeNeural - en-ZA (Male)', 'en-TZ-ElimuNeural - en-TZ (Male)', 'en-TZ-ImaniNeural - en-TZ (Female)', 'en-GB-LibbyNeural - en-GB (Female)', 'en-GB-MaisieNeural - en-GB (Female)', 'en-GB-RyanNeural - en-GB (Male)', 'en-GB-SoniaNeural - en-GB (Female)', 'en-GB-ThomasNeural - en-GB (Male)', 'en-US-AvaMultilingualNeural - en-US (Female)', 'en-US-AndrewMultilingualNeural - en-US (Male)', 'en-US-EmmaMultilingualNeural - en-US (Female)', 'en-US-BrianMultilingualNeural - en-US (Male)', 'en-US-AvaNeural - en-US (Female)', 'en-US-AndrewNeural - en-US (Male)', 'en-US-EmmaNeural - en-US (Female)', 'en-US-BrianNeural - en-US (Male)', 'en-US-AnaNeural - en-US (Female)', 'en-US-AriaNeural - en-US (Female)', 'en-US-ChristopherNeural - en-US (Male)', 'en-US-EricNeural - en-US (Male)', 'en-US-GuyNeural - en-US (Male)', 'en-US-JennyNeural - en-US (Female)', 'en-US-MichelleNeural - en-US (Female)', 'en-US-RogerNeural - en-US (Male)', 'en-US-SteffanNeural - en-US (Male)', 'et-EE-AnuNeural - et-EE (Female)', 'et-EE-KertNeural - et-EE (Male)', 'fil-PH-AngeloNeural - fil-PH (Male)', 'fil-PH-BlessicaNeural - fil-PH (Female)', 'fi-FI-HarriNeural - fi-FI (Male)', 'fi-FI-NooraNeural - fi-FI (Female)', 'fr-BE-CharlineNeural - fr-BE (Female)', 'fr-BE-GerardNeural - fr-BE (Male)', 'fr-CA-ThierryNeural - fr-CA (Male)', 'fr-CA-AntoineNeural - fr-CA (Male)', 'fr-CA-JeanNeural - fr-CA (Male)', 'fr-CA-SylvieNeural - fr-CA (Female)', 'fr-FR-VivienneMultilingualNeural - fr-FR (Female)', 'fr-FR-RemyMultilingualNeural - fr-FR (Male)', 'fr-FR-DeniseNeural - fr-FR (Female)', 'fr-FR-EloiseNeural - fr-FR (Female)', 'fr-FR-HenriNeural - fr-FR (Male)', 'fr-CH-ArianeNeural - fr-CH (Female)', 'fr-CH-FabriceNeural - fr-CH (Male)', 'gl-ES-RoiNeural - gl-ES (Male)', 'gl-ES-SabelaNeural - gl-ES (Female)', 'ka-GE-EkaNeural - ka-GE (Female)', 'ka-GE-GiorgiNeural - ka-GE (Male)', 'de-AT-IngridNeural - de-AT (Female)', 'de-AT-JonasNeural - de-AT (Male)', 'de-DE-SeraphinaMultilingualNeural - de-DE (Female)', 'de-DE-FlorianMultilingualNeural - de-DE (Male)', 'de-DE-AmalaNeural - de-DE (Female)', 'de-DE-ConradNeural - de-DE (Male)', 'de-DE-KatjaNeural - de-DE (Female)', 'de-DE-KillianNeural - de-DE (Male)', 'de-CH-JanNeural - de-CH (Male)', 'de-CH-LeniNeural - de-CH (Female)', 'el-GR-AthinaNeural - el-GR (Female)', 'el-GR-NestorasNeural - el-GR (Male)', 'gu-IN-DhwaniNeural - gu-IN (Female)', 'gu-IN-NiranjanNeural - gu-IN (Male)', 'he-IL-AvriNeural - he-IL (Male)', 'he-IL-HilaNeural - he-IL (Female)', 'hi-IN-MadhurNeural - hi-IN (Male)', 'hi-IN-SwaraNeural - hi-IN (Female)', 'hu-HU-NoemiNeural - hu-HU (Female)', 'hu-HU-TamasNeural - hu-HU (Male)', 'is-IS-GudrunNeural - is-IS (Female)', 'is-IS-GunnarNeural - is-IS (Male)', 'id-ID-ArdiNeural - id-ID (Male)', 'id-ID-GadisNeural - id-ID (Female)', 'ga-IE-ColmNeural - ga-IE (Male)', 'ga-IE-OrlaNeural - ga-IE (Female)', 'it-IT-GiuseppeNeural - it-IT (Male)', 'it-IT-DiegoNeural - it-IT (Male)', 'it-IT-ElsaNeural - it-IT (Female)', 'it-IT-IsabellaNeural - it-IT (Female)', 'ja-JP-KeitaNeural - ja-JP (Male)', 'ja-JP-NanamiNeural - ja-JP (Female)', 'jv-ID-DimasNeural - jv-ID (Male)', 'jv-ID-SitiNeural - jv-ID (Female)', 'kn-IN-GaganNeural - kn-IN (Male)', 'kn-IN-SapnaNeural - kn-IN (Female)', 'kk-KZ-AigulNeural - kk-KZ (Female)', 'kk-KZ-DauletNeural - kk-KZ (Male)', 'km-KH-PisethNeural - km-KH (Male)', 'km-KH-SreymomNeural - km-KH (Female)', 'ko-KR-HyunsuNeural - ko-KR (Male)', 'ko-KR-InJoonNeural - ko-KR (Male)', 'ko-KR-SunHiNeural - ko-KR (Female)', 'lo-LA-ChanthavongNeural - lo-LA (Male)', 'lo-LA-KeomanyNeural - lo-LA (Female)', 'lv-LV-EveritaNeural - lv-LV (Female)', 'lv-LV-NilsNeural - lv-LV (Male)', 'lt-LT-LeonasNeural - lt-LT (Male)', 'lt-LT-OnaNeural - lt-LT (Female)', 'mk-MK-AleksandarNeural - mk-MK (Male)', 'mk-MK-MarijaNeural - mk-MK (Female)', 'ms-MY-OsmanNeural - ms-MY (Male)', 'ms-MY-YasminNeural - ms-MY (Female)', 'ml-IN-MidhunNeural - ml-IN (Male)', 'ml-IN-SobhanaNeural - ml-IN (Female)', 'mt-MT-GraceNeural - mt-MT (Female)', 'mt-MT-JosephNeural - mt-MT (Male)', 'mr-IN-AarohiNeural - mr-IN (Female)', 'mr-IN-ManoharNeural - mr-IN (Male)', 'mn-MN-BataaNeural - mn-MN (Male)', 'mn-MN-YesuiNeural - mn-MN (Female)', 'ne-NP-HemkalaNeural - ne-NP (Female)', 'ne-NP-SagarNeural - ne-NP (Male)', 'nb-NO-FinnNeural - nb-NO (Male)', 'nb-NO-PernilleNeural - nb-NO (Female)', 'ps-AF-GulNawazNeural - ps-AF (Male)', 'ps-AF-LatifaNeural - ps-AF (Female)', 'fa-IR-DilaraNeural - fa-IR (Female)', 'fa-IR-FaridNeural - fa-IR (Male)', 'pl-PL-MarekNeural - pl-PL (Male)', 'pl-PL-ZofiaNeural - pl-PL (Female)', 'pt-BR-ThalitaNeural - pt-BR (Female)', 'pt-BR-AntonioNeural - pt-BR (Male)', 'pt-BR-FranciscaNeural - pt-BR (Female)', 'pt-PT-DuarteNeural - pt-PT (Male)', 'pt-PT-RaquelNeural - pt-PT (Female)', 'ro-RO-AlinaNeural - ro-RO (Female)', 'ro-RO-EmilNeural - ro-RO (Male)', 'ru-RU-DmitryNeural - ru-RU (Male)', 'ru-RU-SvetlanaNeural - ru-RU (Female)', 'sr-RS-NicholasNeural - sr-RS (Male)', 'sr-RS-SophieNeural - sr-RS (Female)', 'si-LK-SameeraNeural - si-LK (Male)', 'si-LK-ThiliniNeural - si-LK (Female)', 'sk-SK-LukasNeural - sk-SK (Male)', 'sk-SK-ViktoriaNeural - sk-SK (Female)', 'sl-SI-PetraNeural - sl-SI (Female)', 'sl-SI-RokNeural - sl-SI (Male)', 'so-SO-MuuseNeural - so-SO (Male)', 'so-SO-UbaxNeural - so-SO (Female)', 'es-AR-ElenaNeural - es-AR (Female)', 'es-AR-TomasNeural - es-AR (Male)', 'es-BO-MarceloNeural - es-BO (Male)', 'es-BO-SofiaNeural - es-BO (Female)', 'es-CL-CatalinaNeural - es-CL (Female)', 'es-CL-LorenzoNeural - es-CL (Male)', 'es-ES-XimenaNeural - es-ES (Female)', 'es-CO-GonzaloNeural - es-CO (Male)', 'es-CO-SalomeNeural - es-CO (Female)', 'es-CR-JuanNeural - es-CR (Male)', 'es-CR-MariaNeural - es-CR (Female)', 'es-CU-BelkysNeural - es-CU (Female)', 'es-CU-ManuelNeural - es-CU (Male)', 'es-DO-EmilioNeural - es-DO (Male)', 'es-DO-RamonaNeural - es-DO (Female)', 'es-EC-AndreaNeural - es-EC (Female)', 'es-EC-LuisNeural - es-EC (Male)', 'es-SV-LorenaNeural - es-SV (Female)', 'es-SV-RodrigoNeural - es-SV (Male)', 'es-GQ-JavierNeural - es-GQ (Male)', 'es-GQ-TeresaNeural - es-GQ (Female)', 'es-GT-AndresNeural - es-GT (Male)', 'es-GT-MartaNeural - es-GT (Female)', 'es-HN-CarlosNeural - es-HN (Male)', 'es-HN-KarlaNeural - es-HN (Female)', 'es-MX-DaliaNeural - es-MX (Female)', 'es-MX-JorgeNeural - es-MX (Male)', 'es-NI-FedericoNeural - es-NI (Male)', 'es-NI-YolandaNeural - es-NI (Female)', 'es-PA-MargaritaNeural - es-PA (Female)', 'es-PA-RobertoNeural - es-PA (Male)', 'es-PY-MarioNeural - es-PY (Male)', 'es-PY-TaniaNeural - es-PY (Female)', 'es-PE-AlexNeural - es-PE (Male)', 'es-PE-CamilaNeural - es-PE (Female)', 'es-PR-KarinaNeural - es-PR (Female)', 'es-PR-VictorNeural - es-PR (Male)', 'es-ES-AlvaroNeural - es-ES (Male)', 'es-ES-ElviraNeural - es-ES (Female)', 'es-US-AlonsoNeural - es-US (Male)', 'es-US-PalomaNeural - es-US (Female)', 'es-UY-MateoNeural - es-UY (Male)', 'es-UY-ValentinaNeural - es-UY (Female)', 'es-VE-PaolaNeural - es-VE (Female)', 'es-VE-SebastianNeural - es-VE (Male)', 'su-ID-JajangNeural - su-ID (Male)', 'su-ID-TutiNeural - su-ID (Female)', 'sw-KE-RafikiNeural - sw-KE (Male)', 'sw-KE-ZuriNeural - sw-KE (Female)', 'sw-TZ-DaudiNeural - sw-TZ (Male)', 'sw-TZ-RehemaNeural - sw-TZ (Female)', 'sv-SE-MattiasNeural - sv-SE (Male)', 'sv-SE-SofieNeural - sv-SE (Female)', 'ta-IN-PallaviNeural - ta-IN (Female)', 'ta-IN-ValluvarNeural - ta-IN (Male)', 'ta-MY-KaniNeural - ta-MY (Female)', 'ta-MY-SuryaNeural - ta-MY (Male)', 'ta-SG-AnbuNeural - ta-SG (Male)', 'ta-SG-VenbaNeural - ta-SG (Female)', 'ta-LK-KumarNeural - ta-LK (Male)', 'ta-LK-SaranyaNeural - ta-LK (Female)', 'te-IN-MohanNeural - te-IN (Male)', 'te-IN-ShrutiNeural - te-IN (Female)', 'th-TH-NiwatNeural - th-TH (Male)', 'th-TH-PremwadeeNeural - th-TH (Female)', 'tr-TR-AhmetNeural - tr-TR (Male)', 'tr-TR-EmelNeural - tr-TR (Female)', 'uk-UA-OstapNeural - uk-UA (Male)', 'uk-UA-PolinaNeural - uk-UA (Female)', 'ur-IN-GulNeural - ur-IN (Female)', 'ur-IN-SalmanNeural - ur-IN (Male)', 'ur-PK-AsadNeural - ur-PK (Male)', 'ur-PK-UzmaNeural - ur-PK (Female)', 'uz-UZ-MadinaNeural - uz-UZ (Female)', 'uz-UZ-SardorNeural - uz-UZ (Male)', 'vi-VN-HoaiMyNeural - vi-VN (Female)', 'vi-VN-NamMinhNeural - vi-VN (Male)', 'cy-GB-AledNeural - cy-GB (Male)', 'cy-GB-NiaNeural - cy-GB (Female)', 'zu-ZA-ThandoNeural - zu-ZA (Female)', 'zu-ZA-ThembaNeural - zu-ZA (Male)'] Default: ""

    The input value that is provided in the "Select Voice" Dropdown component.

    rate float Default: 0

    The input value that is provided in the "Speech Rate Adjustment (%)" Slider component.

    pitch float Default: 0

    The input value that is provided in the "Pitch Adjustment (Hz)" Slider component.

    Returns tuple of 2 elements [0] filepath

    The output value that appears in the "Generated Audio" Audio component.

    [1] str

    The output value that appears in the "Warning" Markdown component.

    Provide full code with app.py and index.html and guide how to setup the project

  2. Assistant

    To help you connect the Edge TTS Text-to-Speech API to your website using Flask, I've prepared the full code for app.py, index.html, and result.html, along with a step-by-step guide on how to set up the project.


    Project Setup Guide

    Prerequisites

    • Python 3.x installed on your system.
    • Basic knowledge of Python and Flask.
    • An internet connection to install dependencies.

    Step 1: Set Up the Project Directory

    Create a new directory for your project. Let's call it edge_tts_project (you can name it whatever you like).

    mkdir edge_tts_project
    cd edge_tts_project
    

    Step 2: Install Required Python Packages

    Install Flask and gradio_client using pip.

    pip install flask gradio_client
    

    Step 3: Create the app.py File

    Create a new file named app.py inside your project directory and paste the following code into it:

    from flask import Flask, render_template, request, send_file
    from gradio_client import Client
    import os
    from shutil import copyfile
    
    app = Flask(__name__)
    
    # Define the list of voices
    voices = [
        "",  # Default empty
        "en-US-JennyNeural - en-US (Female)",
        "en-US-GuyNeural - en-US (Male)",
        "en-GB-LibbyNeural - en-GB (Female)",
        "en-GB-RyanNeural - en-GB (Male)",
        "es-ES-ElviraNeural - es-ES (Female)",
        "es-ES-AlvaroNeural - es-ES (Male)",
        # Add more voices as needed...
        # Full list can be obtained from the API documentation
    ]
    
    @app.route('/', methods=['GET', 'POST'])
    def index():
        if request.method == 'POST':
            text = request.form['text']
            voice = request.form.get('voice', '')
            rate = request.form.get('rate', 0)
            pitch = request.form.get('pitch', 0)
    
            try:
                rate = float(rate)
                pitch = float(pitch)
            except ValueError:
                rate = 0
                pitch = 0
    
            client = Client("innoai/Edge-TTS-Text-to-Speech")
            result = client.predict(
                text=text,
                voice=voice.split(" - ")[0],  # Extract the voice ID
                rate=rate,
                pitch=pitch,
                api_name="/predict"
            )
    
            audio_filepath = result[0]
            warning = result[1]
    
            # Ensure the static/output directory exists
            output_dir = os.path.join('static', 'output')
            if not os.path.exists(output_dir):
                os.makedirs(output_dir)
    
            # Create a unique filename for the audio file
            output_filename = 'output.wav'
            output_path = os.path.join(output_dir, output_filename)
            copyfile(audio_filepath.name, output_path)
    
            return render_template('result.html', audio_file='output/' + output_filename, warning=warning)
        else:
            # GET request, render the form
            return render_template('index.html', voices=voices)
    
    if __name__ == '__main__':
        app.run(debug=True)
    

    Step 4: Create the Templates Directory

    Create a templates directory inside your project directory to hold the HTML templates.

    mkdir templates
    

    Step 5: Create index.html

    Create a file named index.html inside the templates directory and paste the following code:

    <!DOCTYPE html>
    <html>
    <head>
        <title>Edge TTS Text-to-Speech</title>
    </head>
    <body>
        <h1>Edge TTS Text-to-Speech</h1>
        <form method="post">
            <label for="text">Input Text:</label><br>
            <textarea id="text" name="text" rows="4" cols="50">Hello!!</textarea><br><br>
    
            <label for="voice">Select Voice:</label><br>
            <select id="voice" name="voice">
                {% for voice in voices %}
                <option value="{{ voice }}">{{ voice }}</option>
                {% endfor %}
            </select><br><br>
    
            <label for="rate">Speech Rate Adjustment (%):</label><br>
            <input type="range" id="rate" name="rate" min="-100" max="100" value="0"><br><br>
    
            <label for="pitch">Pitch Adjustment (Hz):</label><br>
            <input type="range" id="pitch" name="pitch" min="-50" max="50" value="0"><br><br>
    
            <input type="submit" value="Generate Audio">
        </form>
    </body>
    </html>
    

    Step 6: Create result.html

    Create a file named result.html inside the templates directory and paste the following code:

    <!DOCTYPE html>
    <html>
    <head>
        <title>Edge TTS Text-to-Speech Result</title>
    </head>
    <body>
        <h1>Generated Audio</h1>
        <audio controls>
            <source src="{{ url_for('static', filename=audio_file) }}" type="audio/wav">
            Your browser does not support the audio element.
        </audio>
        <br>
        {% if warning %}
        <p><strong>Warning:</strong> {{ warning }}</p>
        {% endif %}
    
        <a href="{{ url_for('index') }}">Back to Home</a>
    </body>
    </html>
    

    Step 7: Create the Static Directory

    Create a static directory for static files like the generated audio.

    mkdir static
    mkdir static/output
    

    Step 8: Run the Flask App

    Run the app using the following command:

    python app.py
    

    You should see output similar to:

     * Serving Flask app "app" (lazy loading)
     * Environment: production
       WARNING: Do not use the development server in a production environment.
       Use a production WSGI server instead.
     * Debug mode: on
     * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
     * Restarting with stat
     * Debugger is active!
     * Debugger PIN: 123-456-789
    

    Step 9: Access the Application

    Open your web browser and go to http://127.0.0.1:5000/. You should see the Edge TTS Text-to-Speech interface.

    Step 10: Test the Application

    1. Input Text: Enter the text you want to synthesize.
    2. Select Voice: Choose a voice from the dropdown menu.
    3. Speech Rate Adjustment (%): Adjust the rate between -100% to 100%.
    4. Pitch Adjustment (Hz): Adjust the pitch between -50Hz to 50Hz.
    5. Generate Audio: Click the button to generate the audio.

    After submitting, you'll be redirected to a page where you can listen to the generated audio.


    Note on the Voice List

    In the voices list within app.py, only a few sample voices are included for brevity. To get the full list of available voices, you can refer to the API documentation or extract them programmatically. Here's how you can update the voices list:

    # Define the full list of voices
    voices = [
        "",  # Default empty
        "af-ZA-AdriNeural - af-ZA (Female)",
        "af-ZA-WillemNeural - af-ZA (Male)",
        "sq-AL-AnilaNeural - sq-AL (Female)",
        "sq-AL-IlirNeural - sq-AL (Male)",
        "am-ET-AmehaNeural - am-ET (Male)",
        "am-ET-MekdesNeural - am-ET (Female)",
        # ... (include all voices as provided in the documentation)
    ]
    

    Alternatively, you can store the voices in a separate JSON or text file and load them into your Flask app to keep your code organized.


    Additional Information

    • Error Handling: The code includes basic error handling for converting rate and pitch values.
    • Static Files: Generated audio files are stored in static/output. Ensure this directory exists.
    • Debug Mode: app.run(debug=True) is set for development purposes. Disable debug mode in production.
    • Template Rendering: The app uses templates for rendering HTML pages.

    Summary

    You've now set up a Flask application that connects to the Edge TTS Text-to-Speech API using the gradio_client. Users can input text, select a voice, adjust speech rate and pitch, and generate audio directly from your website.

    Feel free to customize the templates and add additional features like:

    • Displaying the input text alongside the audio.
    • Providing more detailed error messages.
    • Expanding the voice list dynamically.

    If you have any questions or need further assistance, don't hesitate to ask!

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.