Playing .mp3 file in flask template (jinja)

23 Views Asked by At

I have an audio file, speech.mp3 which I generate from :

@game_views.route('/loadGame', methods=['POST'])
def game_page():
    result = request.form.get('gameChoice')
    word = getWordList(result)
    language = 'en'
    output = gTTS(text=word, lang=language, slow=False)
    output.save("speech.mp3")
  
    #playsound("speech.mp3")
    return render_template("game.html", result=result, word=word, sound=output)

In my game.html template, however, I would like to play the word that I was about to randomly get. I am unsure how to do this. So far, I have tried :

{% block content %}
{% if current_user.is_authenticated %}

<h3> Hi {{ current_user.username }}! </h3>

  <h4> Difficulty: {{result}} </h4>
  <br>
  <h4> Word: {{word}} </h4>

    <audio src="speech.mp3" controls></audio>

  {% endif %}
{% endblock %}

Any help would be greatly appreciated on how to do this task.

0

There are 0 best solutions below