vishal-h

vishal-h

Audio streaming gives an error while using Elixir Req

There’s a python/fastapi service that streams audio files. I don’t have access to the code of this service.

This works fine and the audio can be played.

<audio controls src="some/audio/url">
    Your browser does not support the <code>audio</code> element.
</audio>

This one doesn’t

Mix.install([
  {:req, "~> 0.4.0"}
])
url = "some/audio/url"

Req.get!(url, into: IO.stream())
|> Stream.each(&IO.inspect/1)
|> Stream.run()

The following error is thrown

** (ArgumentError) errors were found at the given arguments:

  * 2nd argument: not valid character data (an iodata term)

    (stdlib 4.0.1) io.erl:99: :io.put_chars(:standard_io, <<0, 0, 0, 24, 102, ...>>)
    (req 0.4.5) lib/req/steps.ex:760: anonymous fn/3 in Req.Steps.finch_stream_into_collectable/5
    (finch 0.16.0) lib/finch/http1/conn.ex:231: Finch.Conn.receive_response/8
    (finch 0.16.0) lib/finch/http1/conn.ex:120: Finch.Conn.request/6
    (finch 0.16.0) lib/finch/http1/pool.ex:45: anonymous fn/8 in Finch.HTTP1.Pool.request/5
    (nimble_pool 1.0.0) lib/nimble_pool.ex:349: NimblePool.checkout!/4
    (finch 0.16.0) lib/finch/http1/pool.ex:38: Finch.HTTP1.Pool.request/5

What am I missing?

Marked As Solved

al2o3cr

al2o3cr

By default, IO.stream is expecting to read and write UTF8-shaped byte sequences.

Raw audio data is definitely not that.

You likely want IO.binstream, though connecting that to an already-open stdio may need additional code.

Last Post!

vishal-h

vishal-h

Yes. That makes sense. Thanks!

Where Next?

Popular in Questions Top

electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
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
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
dblack
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar. I p...
New

Other popular topics Top

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
dokuzbir
I want to highlight html closing tags when i click a html tag. That works in .html files but doesnt work for html.eex templates. How can...
New
Darmani72
If I have a post route which an argument: post /my_post_route/:my_param1, MyController.my_post_handler How would get the post params ...
New
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
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
sergio
Kind of like when jquery came out, it was super necessary. Existing drag and drop libraries have a bunch of baggage to support old browse...
New

We're in Beta

About us Mission Statement