Is there any way to play OGG sound in a forked process of Electron?

I have an application that plays Ogg audios with HTML5 Audio API. I’m facing performance issues when running this program in very slow and old computers with Windows OS. I’m trying to fork a new process in electron and play the audios with a module or a node addon. But I’m not finding a module or a node addon to do this. Is there any module or node addon to play Ogg files and work with electron?

I have tested some npm packages but I don’t get any success with this.

Is really there any way to play sound in a forked process of Electron?

When you say “HTML5 Audio API” do you mean the <audio> tag or the Web Audio API? The most important question is where is the performance bottleneck coming from on these old/slow computers, and I’m not sure that playing the audio on an additional thread would help, because the bottleneck is likely in decoding the ogg compression while playing in realtime, and taxing an old cpu with a new process might hurt more than help. I recommend trying to decompress the audio data first in its entirety before playing, and see if that helps. You can do that with the Web Audio API using decodeAudioData(), or if you wanted to use a separate process and avoid decompressing the entire sound to RAM you could do that with a shell exec call to a command line utility like sox or ffmpeg to convert the ogg to a temp uncompressed wav.

I’m using the Web Audio API to play the audios. Would be better if I was using the audio tag? I’ll follow your recommendation to decompress the audio before playing and I’ll check if it helps. To you understand better the problem, is like the audio is cutting out when playing. Now the audio is playing in the renderer process right? I’m using AngularJs to do many other things, so I think that this process is overloaded. So I thought to separate that part of the application to avoid suffer processing concurrent with the rest of the application. The ideia is use the concept of Chrome by separating each tab in a different and isolate process. It makes sense?
This problem does not happen on mid/high performance PCs, only in old/slow PCs like old single core processors.
Thanks for your answer.

Electron already supports the Chrome concept of many processes making for light work, but the API is only designed for two ways of making a new process: spawn a ChildProcess or create a new BrowserWindow. You want to do the latter, to create a player window that you can spawn with the path to an audio file and have it play (you can do this right from your renderer process). This has the additional benefit of protecting your app from crashes involving the most interactive part of your program, since if anything goes critical in the player window short of a raging memory leak, it should only block that window.

I don’t think it would be better to use <audio> because with the Web Audio API you have much more flexibility. So if you’re already using the Web Audio API I assume you’re playing your ogg file using an audio buffer, which likely means your code is already calling decodeAudioData() on the buffer before starting to play it. I would try tweaking the Web Audio latency settings and see if that helps. Start with setting your audio context’s latencyHint to “playback” if you’re getting audio break up on slower machines. Another thing you could try tweaking is lowering the context’s sampling frequency when you instantiate the context (for example it usually defaults to 48khz, you could lower it to 22khz if you don’t care as much about quality to lower overhead). Anyway if you’re really targeting old single core machines (10+ yrs old?), spawning another process likely wouldn’t help because the cpu couldn’t handle multiple threads anyway.

1 Like

I converted all audios to WAV and started playing this format, but I didn’t saw any improvement. That way I’m not sure if the problem is in compression. The evidence I have is that an older version of this same player in VB6 plays audios without much trouble on these computers, but in this new Electron version the audios come out with playback bottlenecks. It is as like the audio were stopping milliseconds while playing. I know that the VB6 version is native to Windows and will work better in this situation, but it was in this sense that I had the idea of making the C ++ addon to play the audio to try to have the same performance. Do you know any techniques that I can debug my application to find where is the central point of this problem?
Many thanks!

The audio stuttering you are describing sounds like a buffer underrun. It may just be that the overhead of all of the components of Electron, and the assumptions made by Chromium’s audio engine, plus whatever UI overhead your app may incur, are too much for the old hardware to be able to handle. Did you try tweaking latencyHint? Can you post some of your code? On these old computers are you able to run Chrome and use a simple example audio playback page like https://webaudioapi.com/samples/volume/?