r/PyScript • • Oct 07 '22

Question about pyscript

Could I please ask of there is any way for pyscript to cause the html page to play a sound when an if statement is true?

I've tried googling and wasn't able to find an answer to this.

Play sound nor pydub works.

3 Upvotes

5 comments sorted by

View all comments

Show parent comment

1

u/Best_Championship835 Feb 24 '23

u/TheSwami Do you happen to know why this is not working then? Thanks.

<script defer="" src="https://pyscript.net/alpha/pyscript.js"></script>

<py-script>

from js import alert, prompt, localStorage, window, confirm, Audio

import time

import random

import re

horn = Audio.new("https://github.com/goldfire/howler.js/blob/master/examples/3d/assets/sprite.mp3?raw=true")

user_answer = str(prompt("play? (yes) or (no)"))

if user_answer.lower() == 'yes':

horn.play()

print('yes')

print('end')

</py-script>

1

u/TheSwami Feb 25 '23

Traveling today, so I can’t try it out live. Do you get any errors onscreen or in the developer console?

Should just be defer not defer=“”, that’d be worth changing.

Also, you may want to use the most recent version of PyScript, unless you have a specific reason to use the alpha. `<script defer src="https://pyscript.net/releases/2022.12.1/pyscript.js"></script>