Sound w/ VPython Web

360 views
Skip to first unread message

Mark Schaedel

unread,
Nov 12, 2021, 2:45:13 PM11/12/21
to Glowscript Users
Hello everyone,

I'd really like to use sound in my VPython Web programs. I did a quick search of the group here and wasn't able to find anything.

There is a JS library Tone.js (https://tonejs.github.io/) that I think would be perfect for this, but I'm having trouble figuring out how to import it. Any advice?

Thanks,
Mark

Bruce Sherwood

unread,
Nov 12, 2021, 4:24:45 PM11/12/21
to Glowscript Users

roberto...@gmail.com

unread,
Nov 13, 2021, 5:51:17 PM11/13/21
to Glowscript Users
Here was my attempt to load the p5.speech library using get_library()


Here's my most recent attempt using sound     
using APIs ( WebAudio API and  WebSpeech API ) 
already included in many browsers ( so I don't use get_library() ):

- - WARNING... the audio tones are LOUD !!!   
- - WARNING... the audio tones are LOUD !!!  turn your volume down!!

The audio tones are started when the red sphere is clicked.

- - WARNING... the audio tones are LOUD !!! 
- - WARNING... the audio tones are LOUD !!!  turn your volume down!!
(I have not figured out how to control the volume).


This extends my attempt to use WebSpeech API

Unfortunately, I don't have succinct examples yet... 
I am only getting speech and sound to work... but I have little control of them.

(By the way, these programs are just a way to try out various speech and audio features.
I am not trying to develop a program to animate the earth in orbit.)

rob salgado
(robphy)

On Friday, November 12, 2021 at 3:24:45 PM UTC-6 Bruce Sherwood wrote:
See https://www.glowscript.org/docs/VPythonDocs/files.html

Bruce

Bruce Sherwood

unread,
Nov 13, 2021, 6:11:41 PM11/13/21
to Glowscript Users
Interesting, Rob. Thanks for doing this research.

Bruce

Mark Schaedel

unread,
Nov 15, 2021, 10:10:17 AM11/15/21
to Glowscript Users
Here is a small example I put together based on what I found. Thanks Rob and Bruce.

Rob Salgado

unread,
Nov 15, 2021, 12:32:20 PM11/15/21
to glowscri...@googlegroups.com
Hi, Mark.

That's neat! Glad you were able to get some control of the audio.
I'm now inspired to update my old circular light-clock programs from
VPython 2.3 to (Web VPython) GlowScript 3.x .

In both glowscript.org and trinket.io,
it seems one has to click on the scene to get the audio to make the sound.
This seemed to be the case on Chrome and Edge on WIndows 10.
On Firefox, no interaction was needed after starting the program.
I couldn't get the sound to work on my iPhone.

In any case, it looks and sounds good.

rob salgado
(robphy)
> --
>
> ---
> You received this message because you are subscribed to a topic in the Google Groups "Glowscript Users" group.
> To unsubscribe from this topic, visit https://groups.google.com/d/topic/glowscript-users/6BPyFtY56Mc/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to glowscript-use...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/glowscript-users/931a9575-6181-416c-967b-76cad52228d0n%40googlegroups.com.

Mark Schaedel

unread,
Nov 15, 2021, 1:17:13 PM11/15/21
to Glowscript Users
What I found is that each tone generator can really only be used once, so I made a function that calls a new one up every time a sound is required.

Michael Burns-Kaurin

unread,
Feb 10, 2025, 4:33:45 PMFeb 10
to Glowscript Users
Found this via a google search, just what I needed to recreate a thirty-year-old program written in DOS True BASIC.  Many thanks to Mark Schaedel.
Reply all
Reply to author
Forward
0 new messages