Navigation

    Aodyo Instruments

    Aodyo Community

    • Register
    • Login
    • Search
    • Recent
    • Categories
    • Search
    1. Home
    2. cloudytech
    C
    • Profile
    • Following
    • Followers
    • Topics
    • Posts
    • Groups

    cloudytech

    @cloudytech

    1
    Posts
    2
    Profile views
    0
    Followers
    0
    Following
    Joined Last Online

    cloudytech Follow

    Best posts made by cloudytech

    This user hasn't posted anything yet.

    Latest posts made by cloudytech

    • Play audio on local computer

      I am trying to create a website where users can input text, and the text will be read out on my local machine.

      To achieve this, I have used a simple Flask app with Google cloud text to speech, and am deploying it through Google App Engine. The app is functional, and no errors appear in the app engine error log, however, the audio will not play.

      I am wondering how to send audio from the app to be played by my local computer. Is it possible? Or do I need to use a completely different method? I'm very new to all these tools.

      Here is my main.py:

      from flask import Flask, render_template, send_file, request
          from gtts import gTTS
          from google.cloud import texttospeech
          import os
          import tempfile
          from playsound import playsound
      
          app = Flask(__name__)
      
      
          @app.route("/")
          def homepage():
              return render_template("page.html", title="HOME PAGE")
      
          @app.route('/', methods=['GET','POST'])
          def index():
              if request.method == "POST":
                  text = request.form['text']
      
                  os.environ["GOOGLE_APPLICATION_CREDENTIALS"]="credentials.json"
      
                  client = texttospeech.TextToSpeechClient()
                  input_text = texttospeech.types.SynthesisInput(text=text)
                  voice = texttospeech.types.VoiceSelectionParams(
                      language_code='en-US',
                      name='en-US-Standard-C',
                      ssml_gender=texttospeech.enums.SsmlVoiceGender.FEMALE)
      
                  audio_config = texttospeech.types.AudioConfig(
                      audio_encoding=texttospeech.enums.AudioEncoding.MP3)
      
                  response = client.synthesize_speech(input_text, voice, audio_config)
      
                  # The response's audio_content is binary.
                  with open('/tmp/output.mp3', 'wb') as out:
                      out.write(response.audio_content)
                      os.system("start output.mp3")
                  thankyou = "thanks"
                  return thankyou
      
          if __name__ == "__main__":
              app.run(debug=True)
      
      

      Here is page.html:

      <!DOCTYPE html>
      <html lang="en" dir="ltr">
        <head>
          <meta charset="utf-8">
          <title>Talk to Wednesday</title>
        </head>
        <body>
          <h1> Talk to Me </h1>
          <form method="POST">
            <input name="text">
            <input type="submit">
          </form>
        </body>
      </html>
      
      posted in Sylphyo General
      C
      cloudytech