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

stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New
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
yawaramin
In the Dialyzer docs ( http://erlang.org/doc/man/dialyzer.html#requesting-or-suppressing-warnings-in-source-files ), there is a way to tu...
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
itssasanka
Hi all, Trying to get some more clarity over utc_datetime and naive_datetime for Ecto: https://hexdocs.pm/ecto/Ecto.Schema.html#module-...
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
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
kostonstyle
Hi all I want to have a unix time, from the current time plus 1 hour. DateTime.now + 1 hour How to get it in elixir? Thanks
New
wernerlaude
In AR this is so simple @articles = current_user.articles How to do in Ecto? def index(conn, _params) do current_user = conn.assig...
New

Other popular topics Top

belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
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
senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New
yawaramin
In the Dialyzer docs ( http://erlang.org/doc/man/dialyzer.html#requesting-or-suppressing-warnings-in-source-files ), there is a way to tu...
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
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
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
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

We're in Beta

About us Mission Statement