<turbo-stream action="append" target="posts_list"><template>    <div class="postbit" id="147444" data-post-id="147444">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="rgill" src="/assets/icons/user-9f439610.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  rgill
                    <span class="op-star" title="Thread Starter">
                      <img alt="OP" class="op-star-icon" src="/assets/thread-icons/thread-icon-thread-starter-df91e872.png" />
                    </span>
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Got a working version, would you mind reviewing it? I’m still unsure about best practices in elixir so might be doing something blatantly wrong or not following better conventions.</p>
<p><a href="https://github.com/razagill/speakers" class="onebox" target="_blank" rel="noopener nofollow ugc">https://github.com/razagill/speakers</a></p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="147444" data-batch-url="/posts/batch_likers">
                        3
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/is-there-an-elixir-audio-package/26135/12">Post #11</a>
	                </div>
	            </div>
              <div id="likers-container-147444" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="147444"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-most-liked cat-most-liked" title="One of the top 3 liked posts in this thread!"></div>
  </section>
</div>
    <div class="postbit" id="147703" data-post-id="147703">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="OvermindDL1" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/OvermindDL1/120/2677_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  OvermindDL1
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>I’ve no speakers or so to test, but I’ll look over the code right quick since I have a few moments now.  <img src="https://forum.elixirforum.com/images/emoji/apple/slight_smile.png?v=15" title=":slight_smile:" class="emoji" alt=":slight_smile:" loading="lazy" width="20" height="20"></p>
<ul>
<li>
<p><a href="https://github.com/razagill/speakers/blob/master/lib/speakers.ex" class="inline-onebox" rel="noopener nofollow ugc">speakers/lib/speakers.ex at master · sample-usr/speakers · GitHub</a><br>
Mostly defdelegates, nothing special here, examples are short and clean.  I’m not used to seeing docs on the defdelegates themselves, wonder how they render, have you pushed it to hex yet?</p>
</li>
<li>
<p><a href="https://github.com/razagill/speakers/blob/master/lib/speakers/nif_audio.ex" class="inline-onebox" rel="noopener nofollow ugc">speakers/lib/speakers/nif_audio.ex at master · sample-usr/speakers · GitHub</a><br>
Good standard nif module, proper errors.  Could use documentation though (do those work on NIF functions?) even if just for programmer use (doc comments instead of <code>@doc</code>’s).</p>
</li>
<li>
<p><a href="https://github.com/razagill/speakers/blob/master/lib/speakers/player.ex" class="inline-onebox" rel="noopener nofollow ugc">speakers/lib/speakers/player.ex at master · sample-usr/speakers · GitHub</a><br>
Yay specs, love specs, wonder if those come through the defdelegate, if not they should be added there too.  ^.^<br>
Noticing some interesting <code>PlayerValidator</code> calls in here, I’ll look at that file shortly, but I’m wondering why the NIF isn’t validating these and returning appropriate values (so someone can’t bypass these checks for example, by calling the NIF straight).<br>
A curiosity, does the <code>add_to_queue</code> taking a URL accept a <code>file:///some/path/to/file.ogg</code> work?  This isn’t documented.<br>
Otherwise most calls just call to the NIF (they could indeed be defdelegates too).  ^.^</p>
</li>
<li>
<p><a href="https://github.com/razagill/speakers/blob/master/lib/speakers/player_validator.ex" class="inline-onebox" rel="noopener nofollow ugc">speakers/lib/speakers/player_validator.ex at master · sample-usr/speakers · GitHub</a><br>
Hmm yeah these checks should really be checked on the NIF side so the user can’t call the NIF directly to bypass these, and it would save the time from, for example, decoding the URI twice needlessly.  And why not accept an empty schema/host if it’s a <code>file://</code> path anyway so you can default to passing just a filesystem path like <code>/blah/thing/here.mp3</code> or so?</p>
</li>
<li>
<p><a href="https://github.com/razagill/speakers/tree/master/native/speakers_nifaudio" class="inline-onebox" rel="noopener nofollow ugc">speakers/native/speakers_nifaudio at master · sample-usr/speakers · GitHub</a><br>
The <code>README.md</code> here could use updating.  ^.^</p>
</li>
<li>
<p><a href="https://github.com/razagill/speakers/blob/master/native/speakers_nifaudio/Cargo.toml" class="inline-onebox" rel="noopener nofollow ugc">speakers/native/speakers_nifaudio/Cargo.toml at master · sample-usr/speakers · GitHub</a><br>
Simple enough.  Should add yourself as an author though.</p>
</li>
<li>
<p><a href="https://github.com/razagill/speakers/blob/master/native/speakers_nifaudio/src/lib.rs" class="inline-onebox" rel="noopener nofollow ugc">speakers/native/speakers_nifaudio/src/lib.rs at master · sample-usr/speakers · GitHub</a></p>
<ul>
<li>Hmm, it’s a very basic interface, simple for simple playing.  Definitely could use a higher level interface for controlling of sinks and sources and mixing though, but that can be done later.  Instead of lazy allocating the device sink I’m wondering if it would still be better to handle it as a BEAM resource and let the elixir side hold on to it, so it can deallocate it whenever it’s actually ready (either by closing it via a NIF call or by letting it be GC’d).  That would pollute the simple interface though, but it might making a more controlled interface more annoying…</li>
<li>I recommend at least make a way to deallocate the lazy allocated device sink via a NIF call (<code>close_global_sink()</code> or something?), and just let it re-lazy-allocate if it is needed again after that.</li>
<li>There definitely needs to be a way to pass in a binary and some metadata about the binary (type, like raw data, a wave, ogg, whatever) and then instance a memory source from that ran through the decoder appropriate for the type.</li>
<li>Instead of renaming rodio things like <code>play</code> to be <code>resume</code>, even though more accurate, I wonder if it is better to follow rodio’s naming conventions instead, so it’s docs are more relevant…</li>
<li><code>reqwest::get(audio_url)</code> Hmm, I don’t actually know if <code>reqwest</code> supports file paths…  File paths definitely need to be supported somehow though.</li>
<li><code>.expect("Failed to get audio stream");</code> Eh no, actually test if it fails and report a proper <code>{:error, "Failed to get audio stream"}</code> tuple back to elixir instead, ditto with the other <code>expect</code> calls.  <code>expect</code> calls should never ever appear in released/production Rust code!  The rustler error result type is more for program faults, or badarg’s or so, not improper logic or state.</li>
</ul>
</li>
</ul>
<p>Overall it looks like a good start.  I’m getting ideas of a full <code>rodio</code> exposure to elixir, mixing and all.  ^.^</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="147703" data-batch-url="/posts/batch_likers">
                        1
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/is-there-an-elixir-audio-package/26135/13">Post #12</a>
	                </div>
	            </div>
              <div id="likers-container-147703" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="147703"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #12"></div>
  </section>
</div>
    <div class="postbit" id="147939" data-post-id="147939">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="rgill" src="/assets/icons/user-9f439610.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  rgill
                    <span class="op-star" title="Thread Starter">
                      <img alt="OP" class="op-star-icon" src="/assets/thread-icons/thread-icon-thread-starter-df91e872.png" />
                    </span>
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>This is really nice, thanks a bunch for the great review.</p>
<aside class="quote no-group quote-modified" data-username="OvermindDL1" data-post="13" data-topic="26135">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/overminddl1/48/2677_2.png" class="avatar"> OvermindDL1:</div>
<blockquote>
<p><a href="https://github.com/razagill/speakers/blob/master/lib/speakers.ex" class="inline-onebox" rel="noopener nofollow ugc">speakers/lib/speakers.ex at master · sample-usr/speakers · GitHub</a><br>
Mostly defdelegates, nothing special here, examples are short and clean. I’m not used to seeing docs</p>
</blockquote>
</aside>
<p>I have been following Dave Thomas’ course on Elixir and he recommends an approach to only have public methods in the root file and the rest should essentially go to modules of their own (which at least for now I think is a good approach) and then you <code>defdelegate</code> to the module methods.<br>
I haven’t published it to <code>hex</code> yet since I wanted to iron out some stuff and make it a bit more stable-ish (not that anybody is gonna use it right away hehe).</p>
<aside class="quote no-group quote-modified" data-username="OvermindDL1" data-post="13" data-topic="26135">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/overminddl1/48/2677_2.png" class="avatar"> OvermindDL1:</div>
<blockquote>
<p><a href="https://github.com/razagill/speakers/blob/master/lib/speakers/nif_audio.ex" class="inline-onebox" rel="noopener nofollow ugc">speakers/lib/speakers/nif_audio.ex at master · sample-usr/speakers · GitHub</a><br>
Good standard nif module, proper errors. Could use documentation though (do those work on NIF functions?)</p>
</blockquote>
</aside>
<p>Haven’t tried it on NIF modules, but I would add some there as well.</p>
<aside class="quote no-group" data-username="OvermindDL1" data-post="13" data-topic="26135">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/overminddl1/48/2677_2.png" class="avatar"> OvermindDL1:</div>
<blockquote>
<p><a href="https://github.com/razagill/speakers/blob/master/lib/speakers/player.ex" rel="noopener nofollow ugc">https://github.com/razagill/speakers/blob/master/lib/speakers/player.ex </a><br>
Yay specs, love specs, wonder if those come through the defdelegate, if not they should be added there too. ^.^<br>
Noticing some interesting <code>PlayerValidator</code> calls</p>
</blockquote>
</aside>
<p>Specs are awesome <img src="https://forum.elixirforum.com/images/emoji/apple/slight_smile.png?v=15" title=":slight_smile:" class="emoji" alt=":slight_smile:" loading="lazy" width="20" height="20"> and yup, they do come through <code>defdelegate</code>.<br>
I added the validation through <code>PlayerValidator</code> because to be honest I just didn’t know how to do that in <code>rust</code>, I’m only starting to explore <code>rust</code> for this library. If you can point me to some examples, I can rework the validation.<br>
And no, at the moment <code>add_to_queue</code> doesn’t accept <code>file://</code> type paths, though I am definitely going to add that since it’s natively supported by <code>rodio</code>.</p>
<aside class="quote no-group" data-username="OvermindDL1" data-post="13" data-topic="26135">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/overminddl1/48/2677_2.png" class="avatar"> OvermindDL1:</div>
<blockquote>
<p>Hmm, it’s a very basic interface, simple for simple playing. Definitely could use a higher level interface for<br>
controlling of sinks and sources and mixing though, but that can be done later.</p>
</blockquote>
</aside>
<p>That was my first approach as well, but then I kinda got blocked by the <code>elixir</code> → <code>rustler</code> → <code>rust</code> type system and gave up on that to at least have some working version first. If you have any more ideas, I would happily try it again.</p>
<aside class="quote no-group" data-username="OvermindDL1" data-post="13" data-topic="26135">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/overminddl1/48/2677_2.png" class="avatar"> OvermindDL1:</div>
<blockquote>
<p>I recommend at least make a way to deallocate the lazy allocated device sink via a NIF call ( <code>close_global_sink()</code> or something?), and just let it re-lazy-allocate if it is needed again after that.</p>
</blockquote>
</aside>
<p>Yes, that’s actually easy since <code>rodio</code> provides a function to do it already.</p>
<aside class="quote no-group" data-username="OvermindDL1" data-post="13" data-topic="26135">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/overminddl1/48/2677_2.png" class="avatar"> OvermindDL1:</div>
<blockquote>
<p>There definitely needs to be a way to pass in a binary and some metadata about the binary (type, like raw data, a wave, ogg, whatever) and then instance a memory source from that ran through the decoder appropriate for the type</p>
</blockquote>
</aside>
<p>As far as I understood, this is something that <code>rodio</code> does already, I haven’t really tested if it’s based on the file extension or what but you can pass different types of audio URLs and they’ll be played fine. But yeah, I need to research this more and maybe create a struct as <code>AudioURL</code> or something.</p>
<aside class="quote no-group" data-username="OvermindDL1" data-post="13" data-topic="26135">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/overminddl1/48/2677_2.png" class="avatar"> OvermindDL1:</div>
<blockquote>
<p><code>.expect("Failed to get audio stream");</code> Eh no, actually test if it fails and report a proper <code>{:error, "Failed to get audio stream"}</code> tuple back to elixir instead, ditto with the other <code>expect</code> calls. <code>expect</code> calls should never ever appear in released/production Rust code! The rustler error result type is more for program faults, or badarg’s or so, not improper logic or state.</p>
</blockquote>
</aside>
<p>Had no idea how to use <code>expect</code>, I would have read up on error handling in <code>rust</code>. Can you expand a little on why they should never be in production code though?</p>
<aside class="quote no-group" data-username="OvermindDL1" data-post="13" data-topic="26135">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/overminddl1/48/2677_2.png" class="avatar"> OvermindDL1:</div>
<blockquote>
<p>Overall it looks like a good start. I’m getting ideas of a full <code>rodio</code> exposure to elixir, mixing and all. ^.^</p>
</blockquote>
</aside>
<p>Yeah, hopefully, I’ll keep on exposing more <code>rodio</code> functions <img src="https://forum.elixirforum.com/images/emoji/apple/slight_smile.png?v=15" title=":slight_smile:" class="emoji" alt=":slight_smile:" loading="lazy" width="20" height="20"></p>
<p>Thanks again for taking the time and reviewing it <img src="https://forum.elixirforum.com/images/emoji/apple/slight_smile.png?v=15" title=":slight_smile:" class="emoji" alt=":slight_smile:" loading="lazy" width="20" height="20"></p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="147939" data-batch-url="/posts/batch_likers">
                        2
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/is-there-an-elixir-audio-package/26135/14">Post #13</a>
	                </div>
	            </div>
              <div id="likers-container-147939" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="147939"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #13"></div>
  </section>
</div>
    <div class="postbit" id="148046" data-post-id="148046">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="OvermindDL1" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/OvermindDL1/120/2677_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  OvermindDL1
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group" data-username="rgill" data-post="14" data-topic="26135">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/letter_avatar_proxy/v4/letter/r/f17d59/48.png" class="avatar"> rgill:</div>
<blockquote>
<p>That was my first approach as well, but then I kinda got blocked by the <code>elixir</code> → <code>rustler</code> → <code>rust</code> type system and gave up on that to at least have some working version first. If you have any more ideas, I would happily try it again.</p>
</blockquote>
</aside>
<p>Should be a fairly simple mapping, what did you get stuck on in it?</p>
<aside class="quote no-group" data-username="rgill" data-post="14" data-topic="26135">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/letter_avatar_proxy/v4/letter/r/f17d59/48.png" class="avatar"> rgill:</div>
<blockquote>
<p>As far as I understood, this is something that <code>rodio</code> does already, I haven’t really tested if it’s based on the file extension or what but you can pass different types of audio URLs and they’ll be played fine. But yeah, I need to research this more and maybe create a struct as <code>AudioURL</code> or something.</p>
</blockquote>
</aside>
<p>A source can be user defined, rodio just comes with some default things.  For a binary with a ‘type’ you’d instance the proper decoder for the given type (wave, ogg, etc…) and it will return a source for you.  For raw data you can just feed it directly in, though it would need some other information like it’s rate and so forth.</p>
<aside class="quote no-group" data-username="rgill" data-post="14" data-topic="26135">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/letter_avatar_proxy/v4/letter/r/f17d59/48.png" class="avatar"> rgill:</div>
<blockquote>
<p>Had no idea how to use <code>expect</code> , I would have read up on error handling in <code>rust</code> . Can you expand a little on why they should never be in production code though?</p>
</blockquote>
</aside>
<p><code>expect</code> hard panics, bringing down the entire process, this will include the BEAM itself, it should only be used when the system is in an entirely unrecoverable state at that time.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="148046" data-batch-url="/posts/batch_likers">
                        2
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/is-there-an-elixir-audio-package/26135/15">Post #14</a>
	                </div>
	            </div>
              <div id="likers-container-148046" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="148046"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #14"></div>
  </section>
</div>
    <div class="postbit" id="148481" data-post-id="148481">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="rgill" src="/assets/icons/user-9f439610.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  rgill
                    <span class="op-star" title="Thread Starter">
                      <img alt="OP" class="op-star-icon" src="/assets/thread-icons/thread-icon-thread-starter-df91e872.png" />
                    </span>
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group" data-username="OvermindDL1" data-post="15" data-topic="26135">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/overminddl1/48/2677_2.png" class="avatar"> OvermindDL1:</div>
<blockquote>
<p>Should be a fairly simple mapping, what did you get stuck on in it?</p>
</blockquote>
</aside>
<p>I was trying to send an elixir stream down to rust. For instance, on the elixir side I have a file stream that then needs to be sent to the rust code. But what I don’t get is what would be the <code>type</code> for the decoding here <a href="https://github.com/razagill/speakers/blob/master/native/speakers_nifaudio/src/lib.rs#L53" class="inline-onebox" rel="noopener nofollow ugc">speakers/native/speakers_nifaudio/src/lib.rs at master · sample-usr/speakers · GitHub</a></p>
<aside class="quote no-group" data-username="OvermindDL1" data-post="15" data-topic="26135">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/overminddl1/48/2677_2.png" class="avatar"> OvermindDL1:</div>
<blockquote>
<p>A source can be user defined, rodio just comes with some default things. For a binary with a ‘type’ you’d instance the proper decoder for the given type (wave, ogg, etc…) and it will return a source for you. For raw data you can just feed it directly in, though it would need some other information like it’s rate and so forth.</p>
</blockquote>
</aside>
<p>I see, then I’ll add the <code>type</code> as param.</p>
<aside class="quote no-group" data-username="OvermindDL1" data-post="15" data-topic="26135">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/overminddl1/48/2677_2.png" class="avatar"> OvermindDL1:</div>
<blockquote>
<p><code>expect</code> hard panics, bringing down the entire process, this will include the BEAM itself, it should only be used when the system is in an entirely unrecoverable state at that time.</p>
</blockquote>
</aside>
<p>Thanks, I’m going to add better error handling and response on the rust side.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="148481" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/is-there-an-elixir-audio-package/26135/16">Post #15</a>
	                </div>
	            </div>
              <div id="likers-container-148481" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="148481"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #15"></div>
  </section>
</div>
    <div class="postbit" id="148649" data-post-id="148649">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="OvermindDL1" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/OvermindDL1/120/2677_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  OvermindDL1
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group" data-username="rgill" data-post="16" data-topic="26135">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/letter_avatar_proxy/v4/letter/r/f17d59/48.png" class="avatar"> rgill:</div>
<blockquote>
<p>I was trying to send an elixir stream down to rust. For instance, on the elixir side I have a file stream that then needs to be sent to the rust code. But what I don’t get is what would be the <code>type</code> for the decoding here <a href="https://github.com/razagill/speakers/blob/master/native/speakers_nifaudio/src/lib.rs#L53" rel="noopener nofollow ugc">https://github.com/razagill/speakers/blob/master/native/speakers_nifaudio/src/lib.rs#L53 </a></p>
</blockquote>
</aside>
<p>Probably just a <code>&amp;[u8]</code> or some owned variant.  <img src="https://forum.elixirforum.com/images/emoji/apple/slight_smile.png?v=15" title=":slight_smile:" class="emoji" alt=":slight_smile:" loading="lazy" width="20" height="20"></p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="148649" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/is-there-an-elixir-audio-package/26135/17">Post #16</a>
	                </div>
	            </div>
              <div id="likers-container-148649" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="148649"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #16"></div>
  </section>
</div>
    <div class="postbit" id="148657" data-post-id="148657">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="NobbZ" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/NobbZ/120/27235_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  NobbZ
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Well, streams created by <code>File.stream</code> are functions, I doubt you can simply convert them to a slice of bytes.</p>
<p>We already suggested in the slack to either do the Filehandling on the rust side in a dirty NIF or in a port, or to read chunks into a binary and call the NIF repeatedly with those chunks.</p>
<p>That’s a week or two ago…</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="148657" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/is-there-an-elixir-audio-package/26135/18">Post #17</a>
	                </div>
	            </div>
              <div id="likers-container-148657" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="148657"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #17"></div>
  </section>
</div>
    <div class="postbit" id="148658" data-post-id="148658">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="OvermindDL1" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/OvermindDL1/120/2677_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  OvermindDL1
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group" data-username="NobbZ" data-post="18" data-topic="26135">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/nobbz/48/27235_2.png" class="avatar"> NobbZ:</div>
<blockquote>
<p>Well, streams created by <code>File.stream</code> are functions, I doubt you can simply convert them to a slice of bytes.</p>
</blockquote>
</aside>
<p>Oh I’d never say pass an Elixir stream over, rather a stream messages to fill it in (or a complete message of the entire thing).  Reading an elixir stream over and over and over to get the full contents would be so slow in comparison, they aren’t exactly no-cost like Rust streams.  <img src="https://forum.elixirforum.com/images/emoji/apple/wink.png?v=15" title=":wink:" class="emoji" alt=":wink:" loading="lazy" width="20" height="20"></p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="148658" data-batch-url="/posts/batch_likers">
                        2
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/is-there-an-elixir-audio-package/26135/19">Post #18</a>
	                </div>
	            </div>
              <div id="likers-container-148658" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="148658"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #18"></div>
  </section>
</div>
    <div class="postbit" id="149558" data-post-id="149558">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="rgill" src="/assets/icons/user-9f439610.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  rgill
                    <span class="op-star" title="Thread Starter">
                      <img alt="OP" class="op-star-icon" src="/assets/thread-icons/thread-icon-thread-starter-df91e872.png" />
                    </span>
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p><a class="mention" href="/u/nobbz" rel="nofollow">@NobbZ</a> that’s why based on your suggestion in slack I wired up the remote streaming part in <code>rust</code>.<br>
But <a class="mention" href="/u/overminddl1" rel="nofollow">@OvermindDL1</a> just to understand your comment better and wrap my head around it, why exactly can’t we pass the stream to rust?</p>
<aside class="quote no-group" data-username="OvermindDL1" data-post="19" data-topic="26135">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/overminddl1/48/2677_2.png" class="avatar"> OvermindDL1:</div>
<blockquote>
<p>Oh I’d never say pass an Elixir stream over, rather a stream messages to fill it in (or a complete message of the entire thing)</p>
</blockquote>
</aside>
<p>I’m not sure I understood the filling it in using a stream messages part. If I have something like the following</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">IO.stream(:stdio, :line)
|&gt; Speakers.add_to_queue
</code></pre>
<p>how would I pass that as a “streaming message” to <code>rust</code>? If I am completely off base here, please point me to some resources where I can understand this better.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="149558" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/is-there-an-elixir-audio-package/26135/20">Post #19</a>
	                </div>
	            </div>
              <div id="likers-container-149558" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="149558"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #19"></div>
  </section>
</div>
    <div class="postbit" id="149563" data-post-id="149563">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="NobbZ" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/NobbZ/120/27235_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  NobbZ
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group" data-username="rgill" data-post="20" data-topic="26135">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/letter_avatar_proxy/v4/letter/r/f17d59/48.png" class="avatar"> rgill:</div>
<blockquote>
<p>why exactly can’t we pass the stream to rust?</p>
</blockquote>
</aside>
<p>Because what you call a stream can be anything, a function, a struct of an unspecified module, a pid… And nothing but the <code>Stream</code> module knows how to deal with them.</p>
<p>Streams have to be considered opaque.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="149563" data-batch-url="/posts/batch_likers">
                        3
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/is-there-an-elixir-audio-package/26135/21">Post #20</a>
	                </div>
	            </div>
              <div id="likers-container-149563" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="149563"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-most-liked cat-most-liked" title="One of the top 3 liked posts in this thread!"></div>
  </section>
</div>
</template></turbo-stream><turbo-stream action="replace" target="load-more-container"><template><div id="load-more-container" class="load-more-container">
    <a class="load-more-button" data-turbo-stream="true" href="/topics/26135/load_more?page=3">Load more posts (4 remaining)</a>
</div></template></turbo-stream>