Trini

Trini

What is the simplest way to create a first-in, first-out queue to handle binary data that will be consumed from an external process?

what happens is that i am receiving binary data in my (speech recognition) application, but after some time, heap overflow occurs. I thought my memory wasn’t being freed, but that wasn’t the problem… what I think is happening is that recognizer_partial_result and recognizer_final_result overlap causing the error
This is where I manage the application inside a channel:

def handle_in("file_chunk", {:binary, <<samples :: binary>>}, socket) do
    recognizer = GenServer.call(Model, :get_recognizer)
    wave = :vosk.recognizer_accept_waveform(recognizer, samples)
    if  wave == 0 do
      partial = :vosk.recognizer_partial_result(recognizer)
      IO.inspect(wave, label: "------wave------")

      IO.inspect(partial, label: "-------texto--------")
      # :timer.sleep(10)

       {:noreply,  socket}
    else if wave == 1 do
      result = :vosk.recognizer_final_result(recognizer)
      # :vosk.recognizer_reset(recognizer)
      IO.inspect(wave, label: "------wave------")
      IO.inspect(result, label: "------result------")
      # :timer.sleep(1000)

       {:noreply, socket}
      end
    end
    {:noreply,  socket}
  end

and this is the error :

1403: heap overflow
             [error] GenServer #PID<0.720.0> terminating
** (ArgumentError) argument error
    (vosk 915e429) :vosk.recognizer_partial_result(#Reference<0.2495677460.3785490434.237916>)
    (pba 0.1.0) lib/pba_web/channels/room_channel.ex:16: PbaWeb.RoomChannel.handle_in/3
    (phoenix 1.7.2) lib/phoenix/channel/server.ex:317: Phoenix.Channel.Server.handle_info/2
    (stdlib 4.3) gen_server.erl:1123: :gen_server.try_dispatch/4
    (stdlib 4.3) gen_server.erl:1200: :gen_server.handle_msg/6
    (stdlib 4.3) proc_lib.erl:240: :proc_lib.init_p_do_apply/3
Last message: %Phoenix.Socket.Message{topic: "room:lobby", event: "file_chunk", payload: {:binary, <<235, 255, 223, 255, 229, 255, 252, 255, 21, 0, 33, 0, 65, 0, 34, 0, 0, 0, 251, 255, 3, 0, 9, 0, 15, 0, 10, 0, 246, 255, 4, 0, 10, 0, 29, 0, 49, 0, 54, 0, 51, 0, 49, 0, 35, ...>>}, ref: "705", join_ref: "3"}
State: %Phoenix.Socket{assigns: %{}, channel: PbaWeb.RoomChannel, channel_pid: #PID<0.720.0>, endpoint: PbaWeb.Endpoint, handler: PbaWeb.UserSocket, id: nil, joined: true, join_ref: "3", private: %{log_handle_in: :debug, log_join: :info}, pubsub_server: Pba.PubSub, ref: nil, serializer: Phoenix.Socket.V2.JSONSerializer, topic: "room:lobby", transport: :websocket, transport_pid: #PID<0.713.0>}

I think the best way to handle it is with first-in, first-out but the truth is that I am not understanding how to do this in my project with elixir and that it works with my channels in phoenix.
If you have any idea where I can get detailed information on how to do it, I would be very grateful or a better option. I’m really new to the language and I still don’t fully understand it.

First Post!

cmo

cmo

Erlang has a queue module.

You might like to rewrite your if/else if as a case statement. It will read nicer.

Where Next?

Popular in Questions Top

sergio
In Ruby, I can go: User.find_by(email: "foobar@email.com").update(email: "hello@email.com") How can I do something similar in Elixir? ...
New
aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
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
mathew4509
I have a list say x = ["23gh", "56kh", "97mh"] I would like to pass each element to Val in each iteration. Say, in iteration 1 -------...
New
gonzofish
I’m currently trying to understand how to join three tables using Ecto. All the examples I’ve seen use 2, so maybe I’m just missing somet...
New
chewm
Hi guys, nice to meet you to the whole forum, I’m new here, I’m trying to configure visual studio code for elixir, right now the intellis...
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
skosch
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New
lucidguppy
I have a super simple question about elixir - how would I take a file like this foo bar baz and output a new file that enumerates th...
New
jc00ke
Expanding on this topic: https://forum.elixirforum.net/t/map-typespec-question/19217 Let’s say I have a map with required and optional k...
New

Other popular topics Top

pmjoe
I have a relationship of love and hate with Elixir. Lots of things are just absolutely right, but there are some things that are kind of ...
New
jerry
Good day to you all. I have been struggling to get a query involving like and ilike to work. Can anyone assist me on this, please? pro...
New
Jim
As a follow up to my earlier question: I have the code compiling and running but not getting a successful login from the rest server. ...
New
lk-geimfari
What is most correct way to open, read and parse JSON file with poison? For example if we have example.json file in root of some projec...
New
danschultzer
None of the current solutions worked well for me, so I went ahead and built a user management system from scratch. This project took far...
548 27727 240
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
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
fireproofsocks
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? https://hexdocs.pm/ecto/Ecto.Repo.h...
New
AstonJ
by Lance Halvorsen Elixir and Phoenix are generating tremendous excitement as an unbeatable platform for building modern web application...
460 27162 124
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

We're in Beta

About us Mission Statement