rgill

rgill

Hi guys,
New to the forum here and somewhat new to elixir as well. I’ve been going through tutorials and doing the Dave Thomas’ course on elixir, but I’ve been looking to build something in the mean time. I had a project that I wrote in javascript which output sounds through the speakers and I was thinking of porting that to elixir for funsies.

However, I couldn’t find anything related to audio output through google or any package on hex.pm, is there anything already? Does anyone have an idea?
For reference: I was using this package in javascript (https://www.npmjs.com/package/speaker)

Showing Posts 1 to 10

OvermindDL1

OvermindDL1

Hmm, not at all the usual work area for BEAM projects, but I could see someone making a NIF or Port or so being just fine for audio processing. Perhaps ‘you’ should make such a library? :slight_smile:

rgill

rgill OP

Lol, that’s exactly what I was researching :wink:
Looking at rustler right now to get me started (really good packages for audio in rust), maybe I’ll hack something together.

gregvaughn

gregvaughn

Joe Armstrong (late co-creator of Erlang) was doing some fun stuff with SonicPI

OvermindDL1

OvermindDL1

I’d imagine whipping up the Rust rodio library in rustler would make a good setup. :slight_smile:

axelson

axelson

Scenic Core Team

Another set of packages to watch is https://www.membraneframework.org/ although perhaps that’s more focused on streaming than what you’re looking for (it’s also still in beta)

rgill

rgill OP

Update: made a small nif project that uses rodio under the hood. The rust part is able to play the audio, however, now I’m looking on how to stream the file from elixir down to rust, but having some difficultly regarding the types (what are the corresponding rust types for a file stream in elixir?) - need to read up on that.
Essentially I want to make it so that I’ll be able to use File.Stream from elixir and pass it down to rust and then be able to handle pause/play/stop etc.

rgill

rgill OP

Yup thanks, I looked at that but that’s not exactly what I wanted.

OvermindDL1

OvermindDL1

I would just stream chunks of binary to the NIF. You can also have the NIF do it’s own file handling as well (pass it a name). Files on the BEAM directly are actually just Ports (PortDrivers specifically) and they send messages of file data to the process, so it’s no different to you sending binary to the NIF to fill it’s internal buffer. :slight_smile:

rgill

rgill OP

Yup, the types for that binary in rust got me really confused since I couldn’t figure it out. So I ended up writing the streaming part in rust as well. So from elixir you just pass a URL to the audio file and rust fetches it and plays it.
Going to implement some wrapper methods for play/pause/stop and see how it works. Also, is it a good practice to start a nif in a supervision tree?

OvermindDL1

OvermindDL1

Nif’s are just function, nothing to supervise. If however you hold a resource on the elixir side that was given by the NIF and you need to manage it, then yes for that, but you can’t supervise a NIF itself as it’s just a function call. :slight_smile:

Where Next? Top

Trending in Questions Top

RSP87
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
nseaSeb
Hello, I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
RemyXRenard
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
samoloth
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
brecabral
Documentation While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
FlyingNoodle
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New

Other Trending Topics Top

mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Dmk
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
webofbits
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself. My main conc...
#ai
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews