jonast

jonast

Resample 8000Hz s16le for use in Bumblebee whisper model (16000Hz 32f)

Hi folks, what’s the easiest way to use Membrane to resample from PCM single channel 8000Hz sample rate s16le to something I can use in the Whisper bumblebee model? (I believe 16000Hz 32f?)

For simplicity, let’s say I’d like to do this in a LiveBook and I’ve got a Binary of the raw 16bit audio frames loaded in memory

Most Liked

jerzywilczek

jerzywilczek

Membrane Core Team

you should use our FFmpeg SWResample plugin. The docs contain an example of a thing similar to what you want to do, except for the fact that the input is a file instead of a in-memory binary. Let me know if you have any trouble!

jonast

jonast

Thanks so much both, that’s super useful. I can confirm that the resampled audio file plays as intended and the LiveBook no longer crashes

Will have a go at writing a BinarySrc plugin now

jerzywilczek

jerzywilczek

Membrane Core Team
  1. Unfortunately we don’t have a plugin that allows a binary input or output, however it would be very simple to implement if you read the file plugin’s code, probably ~30-40 lines of code.
  2. The aborted state is a result of a crash of the pipeline. I don’t know why the error isn’t present in the cell output. There are two causes to the pipeline crashing. The first one is that as soon as you define a callback (such as handle_element_end_of_stream) for one input case, the automatic implementation disappears, so when :file_src returns end of stream, membrane tries to call Resampling.Pipeline.handle_element_end_of_stream(:file_src, _, _, _) and fails to find an implementation. The fix for this is simple: you need to define
    ...
    
    @impl true
      def handle_element_end_of_stream(:file_sink, _pad, _ctx_, _state) do
        {[playback: :stopped], nil}
      end
    
    @impl true
    def handle_element_end_of_stream(_child, _pad, _ctx, _state) do
      {[], nil}
    end
    
    ...
    
    The second problem is returning the playback: :stopped action, which doesn’t exist in membrane core v0.11. You should return terminate: :normal instead.
  3. Functions that start a pipeline return {:ok, supervisor_pid, pipeline_pid} in case of success, because the pipeline is always spawned under a dedicated supervisor. The supervisor never restarts the pipeline, but it makes sure that the pipeline and its children terminate properly.
  4. The guide you’re referring to uses membrane core v0.7, and is unfortunately out of date : (. The play() function was replaced with returning the playback: :playing action, which you did in your handle_init. I’m sorry the guides are outdated, we decided it would be better for now to focus on releasing core 1.0 and rewrite the old guides after that, since then the API will not change every couple months.
  5. Try playing the files after resampling, since as I mentioned, they might be corrupted due to a bug we are currently having in out swresample plugin ;( We’re working on fixing it as soon as possible!

Hope this helps, let me know if you need anything else!

Where Next?

Popular in Questions Top

_russellb
I want to try my hand at web scraping. What tools/libraries do I need to use. I’m hoping to turn this into something professional so don’...
New
hariharasudhan94
lets say i have a sample like a = 20; b = 10; if (a > b) do {:ok, "a"} end if (a < b) do {:ok, b} end if (a == b) do {:ok, "equa...
New
9mm
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New
albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
johnnyicon
Hi all, I’ve just started learning Elixir and Phoenix Framework, so please pardon my n00bness at this stage. I’m trying to use Postgres...
New
fireproofsocks
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? Ecto.Repo — Ecto v3.14.0 has exampl...
New
JulienCorb
I am trying to implement my new.html.eex file to create new posts on my website. new.html.eex: <h1>Create Post</h1> <%= ...
New
joeerl
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New
aalberti333
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this: ...
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New

Other popular topics Top

baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
New
shahryarjb
Hello, I have map which I want to convert it to string like this: the map: %{last_name: "tavakkoli", name: "shahryar"} the string I ne...
New
Fl4m3Ph03n1x
About me? ( if you have nothing better to do than reading about some random guy in the internet :stuck_out_tongue: ) Hello all, this is ...
New
aesmail
Hello guys, I have finally made it. I created an admin interface for a framework. It’s been on my todo list for years and with the curre...
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
boundedvariable
I am going through the kafka architecture. All the features what the kafka is providing are already in Erlang. I would like hear your opi...
New
rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list. ...
New
shijith.k
I am trying to start a new phoenix project with elixir 1.9, but mix phx.new does not work. It says that ** (Mix) The task "phx.new" could...
New
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
AstonJ
Seen any cool LiveView demos, sample apps or examples? Please post them here! :003:
New

We're in Beta

About us Mission Statement