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)

First 10 of 24 Posts Switch mode

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

stjefim
Hello! Suppose you are building workflow (order / task / payment) processing system with the following requirements: Each workflow con...
New
jonnycharles
I’m in search of an Elixir library that offers PDF generation capabilities similar to Ruby’s Prawn. While there have been discussions abo...
New
spammy
I’m looking to build a personal workflow to quickly deploy web applications written in elixir/phoenix, for local consumption (ie not on t...
New
dli
Before I dive in myself, did anyone successfully sprinkle Hologram into their existing LiveView app? Looking for hints regarding: Addi...
New
roeland
Kia ora, We have been using elixir-google-api to connect to Google Drive. However, with the updates to Tesla due to CVEs this is now bro...
New
bottlenecked
Hi all, I wanted to ask how the community is dealing with post-release steps. Today we have Ecto migrations, which make sure that the db...
New
rahultumpala
Hello, I have an Elixir backend that implements a custom protocol over TCP. I want to load test the backend and assess the performance o...
New

Other Trending Topics Top

JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
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
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve. They are GUI (Emerge) and State management (S...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
ausimian
Emily is an Elixir library that runs Nx computations on Apple’s MLX. Install it as the default Nx backend and Nx, defn, Axon, Nx.Serving,...
New
type1fool
I just stumbled on a newly redesigned elixir-lang.org. :tada: It looks like @Software_Mansion did the work, and I think it is generally a...
New

We're in Beta

About us Mission Statement