1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>
<TITLE> [99s-extend] Newbie, Cowboy + Websocket + Audio Recording
</TITLE>
<LINK REL="Index" HREF="index.html" >
<LINK REL="made" HREF="mailto:extend%40lists.ninenines.eu?Subject=Re%3A%20%5B99s-extend%5D%20Newbie%2C%20Cowboy%20%2B%20Websocket%20%2B%20Audio%20Recording&In-Reply-To=%3CCA%2Bycm%3D5YMMKFpZnfGrOBLu5Jn4WFAiX7BmwbKBti2YsVmJ5JjQ%40mail.gmail.com%3E">
<META NAME="robots" CONTENT="index,nofollow">
<style type="text/css">
pre {
white-space: pre-wrap; /* css-2.1, curent FF, Opera, Safari */
}
</style>
<META http-equiv="Content-Type" content="text/html; charset=us-ascii">
<LINK REL="Previous" HREF="000466.html">
</HEAD>
<BODY BGCOLOR="#ffffff">
<H1>[99s-extend] Newbie, Cowboy + Websocket + Audio Recording</H1>
<B>Juan Matías</B>
<A HREF="mailto:extend%40lists.ninenines.eu?Subject=Re%3A%20%5B99s-extend%5D%20Newbie%2C%20Cowboy%20%2B%20Websocket%20%2B%20Audio%20Recording&In-Reply-To=%3CCA%2Bycm%3D5YMMKFpZnfGrOBLu5Jn4WFAiX7BmwbKBti2YsVmJ5JjQ%40mail.gmail.com%3E"
TITLE="[99s-extend] Newbie, Cowboy + Websocket + Audio Recording">jmrepetti at gmail.com
</A><BR>
<I>Tue Sep 30 12:38:15 CEST 2014</I>
<P><UL>
<LI>Previous message: <A HREF="000466.html">[99s-extend] Newbie, Cowboy + Websocket + Audio Recording
</A></li>
<LI> <B>Messages sorted by:</B>
<a href="date.html#467">[ date ]</a>
<a href="thread.html#467">[ thread ]</a>
<a href="subject.html#467">[ subject ]</a>
<a href="author.html#467">[ author ]</a>
</LI>
</UL>
<HR>
<!--beginarticle-->
<PRE>Thanks, that fixed the error. Now I'm having other but I'll investigate.
On Tue, Sep 30, 2014 at 12:53 AM, Eduardo Gurgel <<A HREF="https://lists.ninenines.eu/listinfo/extend">edgurgel at gmail.com</A>> wrote:
><i> Looking on the output it says:
</I>><i>
</I>><i> *{reason,badarith} *on this line:
</I>><i>
</I>><i> RecorderPid ! {rec, _Frame/binary},
</I>><i>
</I>><i> This may help you somehow.
</I>><i>
</I>><i> BTW, variables starting with _ are usually used to show unused variables
</I>><i> and stop warnings from the compiler.
</I>><i>
</I>><i> On 30 September 2014 05:52, Juan Matías <<A HREF="https://lists.ninenines.eu/listinfo/extend">jmrepetti at gmail.com</A>> wrote:
</I>><i>
</I>>><i> Hello list, I hope this is the right place to ask this.
</I>>><i>
</I>>><i> I'm learning Erlang, and I wanted to create a Cowboy app to record audio
</I>>><i> from a web browser.
</I>>><i>
</I>>><i> Based on the websocket example in the Cowboy source code, I get the user
</I>>><i> mic input and send this input to the websocket.
</I>>><i>
</I>>><i> I created a "recorder" module, which functionality is to save the data to
</I>>><i> the a file.
</I>>><i>
</I>>><i>
</I>>><i> *#rawe_handler.erl*-module(rawec_handler).
</I>>><i> -behaviour(cowboy_websocket_handler).
</I>>><i> ......
</I>>><i> init(_, _, _) ->
</I>>><i> case whereis(recorder) of
</I>>><i> undefined ->
</I>>><i> RecorderPid = recorder:start(),
</I>>><i> register(recorder, RecorderPid);
</I>>><i> _ -> ok
</I>>><i> end,
</I>>><i> {upgrade, protocol, cowboy_websocket}.
</I>>><i> .....
</I>>><i> websocket_handle(_Frame, Req, State) ->
</I>>><i> RecorderPid = whereis(recorder),
</I>>><i> RecorderPid ! {rec, _Frame/binary},
</I>>><i> {ok, Req, State}.
</I>>><i>
</I>>><i> *#recorder.erl*
</I>>><i> -module(recorder).
</I>>><i>
</I>>><i> -export([start/0, recorder_fun/1]).
</I>>><i> -compile([debug_info]).
</I>>><i>
</I>>><i> recorder_fun(IoDevice) ->
</I>>><i> receive
</I>>><i> {rec, Data} ->
</I>>><i> ok = file:write(IoDevice, Data),
</I>>><i> io:format(Data),
</I>>><i> recorder_fun(IoDevice);
</I>>><i> {stop, _} ->
</I>>><i> %%Close file
</I>>><i> file:close(IoDevice)
</I>>><i> end.
</I>>><i>
</I>>><i> start() ->
</I>>><i> {ok, IoDevice} = file:open("/tmp/test_binary.wav", [write,
</I>>><i> binary]),
</I>>><i> spawn(recorder, recorder_fun, [IoDevice]).
</I>>><i>
</I>>><i>
</I>>><i> When I start the console, and allow the microphone on the browser, I see
</I>>><i> this error on the console:
</I>>><i>
</I>>><i> =ERROR REPORT==== 29-Sep-2014::18:13:03 ===
</I>>><i> Ranch listener http had connection process started with
</I>>><i> cowboy_protocol:start_link/4 at <0.178.0> exit with reason:
</I>>><i> *{[{reason,badarith},{mfa,{rawec_handler,websocket_handle,3*}},{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,
</I>>><i> DATA STREAM CONTINUES)
</I>>><i>
</I>>><i> Probably my approach to do this is totally wrong. I there any obvious
</I>>><i> problem here?
</I>>><i> Can someone point me to a right direction?. Maybe I should write directly
</I>>><i> to a file in the *websocket_handle *funcion, but how can I keep a file
</I>>><i> opened during the streaming?
</I>>><i>
</I>>><i> The github repo is here: <A HREF="https://github.com/jmrepetti/rawec">https://github.com/jmrepetti/rawec</A> with the
</I>>><i> whole source code if you want to take a look.
</I>>><i>
</I>>><i>
</I>>><i> Thanks in advance,
</I>>><i> Matias.
</I>>><i>
</I>>><i> _______________________________________________
</I>>><i> Extend mailing list
</I>>><i> <A HREF="https://lists.ninenines.eu/listinfo/extend">Extend at lists.ninenines.eu</A>
</I>>><i> <A HREF="https://lists.ninenines.eu/listinfo/extend">https://lists.ninenines.eu/listinfo/extend</A>
</I>>><i>
</I>>><i>
</I>><i>
</I>><i>
</I>><i> --
</I>><i> Eduardo
</I>><i>
</I>
--
Matías
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <<A HREF="http://lists.ninenines.eu/archives/extend/attachments/20140930/ef46837f/attachment.html">http://lists.ninenines.eu/archives/extend/attachments/20140930/ef46837f/attachment.html</A>>
</PRE>
<!--endarticle-->
<HR>
<P><UL>
<!--threads-->
<LI>Previous message: <A HREF="000466.html">[99s-extend] Newbie, Cowboy + Websocket + Audio Recording
</A></li>
<LI> <B>Messages sorted by:</B>
<a href="date.html#467">[ date ]</a>
<a href="thread.html#467">[ thread ]</a>
<a href="subject.html#467">[ subject ]</a>
<a href="author.html#467">[ author ]</a>
</LI>
</UL>
<hr>
<a href="https://lists.ninenines.eu/listinfo/extend">More information about the Extend
mailing list</a><br>
</body></html>
|