a-shell icon indicating copy to clipboard operation
a-shell copied to clipboard

play sound

Open ifuchs opened this issue 5 years ago • 8 comments

is it possible to play sounds from a-shell?

ifuchs avatar Oct 04 '20 20:10 ifuchs

You can play sounds when running scripts via jsc. JavaScript run through jsc has access to the Web AudioContext.

Thanks. I don't suppose you have (or can point me to) an example which can play an .mp3 file?

On Oct 4, 2020, at 8:23 PM, Henry Heino [email protected] wrote:

You can play sounds when running scripts via jsc. JavaScript run through jsc has access to the Web AudioContext https://developer.mozilla.org/en-US/docs/Web/API/AudioContext.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/holzschu/a-shell/issues/112#issuecomment-703338122, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABLDPSCXQH6PIJJ2ZZACQV3SJEGYBANCNFSM4SD54IEQ.

ifuchs avatar Oct 05 '20 00:10 ifuchs

FWIW, I just noticed that the jsc command in a-shell lacks the interactive UI.

ifuchs avatar Oct 05 '20 01:10 ifuchs

jsc runs JavaScript directly in hterm.html. As such, any document manipulations are reflected there. Through this, it has a sort of interactive UI... For example,

$ cat temp.js
let doc = document.documentElement;
doc.style.filter = "invert(100%)";
$ jsc temp.js

will invert a-Shell's colors. Of course, you can do much more than that, and playing audio is just one example.

Unfortunately, jsc's running JavaScript in the same context as hterm.html (as opposed to say, node) makes it more difficult to access files (at least, I think so -- maybe WasmFs can be used?).

The AudioContext, however can be used to synthesize audio. I'm not sure that this works for you.

Additionally, the open command can be used to open mp3 files.

One way you could play an mp3 is serving it with python -- something like this might work: ** This is an idea -- I have yet to try it. **

$ cd musicDirectory
$ ls
foo.mp3

$ cat playMusic.js
setTimeout(() =>
{
    let audio = new Audio("127.0.0.1:8000/foo.mp3");

    // See https://developer.mozilla.org/en-US/docs/Web/API/HTMLAudioElement/Audio
    audio.addEventListener("canplay", () =>
    {
        audio.play();
    });
}, 1000); // Wait 1 second before playing -- ideally, we would 
// start the server before running jsc, but that requires running
// python3 -m http.server in the background.
$ jsc playMusic.js
$ python -m http.server

If this works, you should be able to automate it using a python script!

Additionally, hterm.html defines a WasmFs object! I'm not sure how, but this might be able to transfer files to js code without sending them via a local server.

Note that there are probably other ways to play an mp3 from aShell -- these are just the ones I could think of.

I hope this is helpful!

Am I correct that there is still no more direct way to play a local MP3 file?

ifuchs avatar Dec 31 '20 15:12 ifuchs

There is now a command to play files (v. 1.6.6): "play". It will play audio and video files, and keep playing if the app is in the background.

holzschu avatar Jan 25 '21 11:01 holzschu

Hi! I am using the play command in a folder with a bunch of mp3 files. Is it possible to add a next-button or autoplay next track?

Smig0l avatar Aug 08 '22 12:08 Smig0l

Good question. I’ll have a look into it, but I’m not sure it’s possible.

holzschu avatar Aug 09 '22 07:08 holzschu