<div dir="ltr">Thanks, that fixed the error. Now I'm having other but I'll investigate. <br><br><br></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Sep 30, 2014 at 12:53 AM, Eduardo Gurgel <span dir="ltr"><<a href="mailto:edgurgel@gmail.com" target="_blank">edgurgel@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Looking on the output it says:<div><br></div><div><b style="font-family:arial,sans-serif;font-size:13px">{reason,badarith} </b><span style="font-family:arial,sans-serif;font-size:13px">on this line: </span></div><span class=""><div><span style="color:rgb(0,128,128);font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:12px;line-height:16.7999992370605px;white-space:pre-wrap"><br></span></div>RecorderPid ! {rec, _Frame/binary},<div><br></div></span><div>This may help you somehow. </div><div><br></div><div>BTW, variables starting with _ are usually used to show unused variables and stop warnings from the compiler.</div></div><div class="gmail_extra"><br><div class="gmail_quote"><div><div class="h5">On 30 September 2014 05:52, Juan Matías <span dir="ltr"><<a href="mailto:jmrepetti@gmail.com" target="_blank">jmrepetti@gmail.com</a>></span> wrote:<br></div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="h5"><div dir="ltr"><div>Hello list, I hope this is the right place to ask this.<br><br></div><div>I'm learning Erlang, and I wanted to create a Cowboy app to record audio from a web browser.<br><br>Based on the websocket example in the Cowboy source code, I get the user mic input and send this input to the websocket.<br><br></div><div>I created a "recorder" module, which functionality is to save the data to the a file.<br><br><b>#rawe_handler.erl<br></b>-module(rawec_handler).<br>-behaviour(cowboy_websocket_handler).<br>......<br>init(_, _, _) -><br>  case whereis(recorder) of<br>    undefined -><br>        RecorderPid = recorder:start(),<br>        register(recorder, RecorderPid);<br>    _ -> ok<br>  end,<br>    {upgrade, protocol, cowboy_websocket}.<br>.....<br>websocket_handle(_Frame, Req, State) -><br>  RecorderPid = whereis(recorder),<br>  RecorderPid ! {rec, _Frame/binary},<br>    {ok, Req, State}.<br><br></div><div><b>#recorder.erl</b><br>-module(recorder).<br><br>-export([start/0, recorder_fun/1]).<br>-compile([debug_info]).<br><br>recorder_fun(IoDevice) -> <br>  receive<br>    {rec, Data} -><br>      ok = file:write(IoDevice, Data),<br>      io:format(Data),<br>      recorder_fun(IoDevice);<br>    {stop, _} -><br>      %%Close file<br>      file:close(IoDevice)<br>    end.<br>    <br>start() -><br>  {ok, IoDevice} = file:open("/tmp/test_binary.wav", [write, binary]),          <br>  spawn(recorder, recorder_fun, [IoDevice]).<br>  <br><br></div><div>When I start the console, and allow the microphone on the browser, I see this error on the console:<br><br>=ERROR REPORT==== 29-Sep-2014::18:13:03 ===<br>Ranch listener http had connection process started with cowboy_protocol:start_link/4 at <0.178.0> exit with reason: <b>{[{reason,badarith},{mfa,{rawec_handler,websocket_handle,3</b>}},{stacktrace,[{rawec_handler,websocket_handle,3,[{file,"src/rawec_handler.erl"},{line,35}]},{cowboy_websocket,handler_call,7,[{file,"src/cowboy_websocket.erl"},{line,588}]},{cowboy_protocol,execute,4,[{file,"src/cowboy_protocol.erl"},{line,435}]}]},{msg,{binary,<<0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0....(ETC, DATA STREAM CONTINUES)<br></div><div><br></div><div>Probably my approach to do this is totally wrong. I there any obvious problem here?<br></div><div>Can someone point me to a right direction?. Maybe I should write directly to a file in the <b>websocket_handle </b>funcion, but how can I keep a file opened during the streaming?<br><br></div><div>The github repo is here: <a href="https://github.com/jmrepetti/rawec" target="_blank">https://github.com/jmrepetti/rawec</a> with the whole source code if you want to take a look.<br><br><br></div><div>Thanks in advance,<br></div><div>Matias.<br>
</div></div>
<br></div></div>_______________________________________________<br>
Extend mailing list<br>
<a href="mailto:Extend@lists.ninenines.eu" target="_blank">Extend@lists.ninenines.eu</a><br>
<a href="https://lists.ninenines.eu/listinfo/extend" target="_blank">https://lists.ninenines.eu/listinfo/extend</a><br>
<br></blockquote></div><span class="HOEnZb"><font color="#888888"><br><br clear="all"><div><br></div>-- <br><div dir="ltr">Eduardo<br></div>
</font></span></div>
</blockquote></div><br><br clear="all"><br>-- <br><div dir="ltr">Matías <br></div>
</div>