[英]Can't record microphone input by using recorderjs in rails environment
I want to record user's voice in my Rails project. 我想在我的Rails项目中记录用户的声音。
So I tried to use [AudioRecorder][1]
, but I couldn't. 因此,我尝试使用
[AudioRecorder][1]
,但不能。 I checked the example HTML works fine by using python -m SimpleHTTPServer
. 我使用
python -m SimpleHTTPServer
检查了示例HTML是否可以正常工作。
Then I copied 'audiodisplay.js', 'main.js', 'recorder.js' and 'recorderWorker.js' to app/assets/javascripts/recorder/
directory. 然后,我将“ audiodisplay.js”,“ main.js”,“ recorder.js”和“ recorderWorker.js”复制到
app/assets/javascripts/recorder/
目录。
And copy sample HTML to app/views/static_pages/home.html.erb
without unnecessary tag: 并将示例HTML复制到
app/views/static_pages/home.html.erb
不要使用不必要的标签:
<style>
...styles for the page
</style>
<div id="viz">
<canvas id="analyser" width="1024" height="500"></canvas>
<canvas id="wavedisplay" width="1024" height="500"></canvas>
</div>
<div id="controls">
<img id="record" src="img/mic128.png" onclick="toggleRecording(this);">
<a id="save" href="#"><img src="img/save.svg"></a>
</div>
The graph changes by surrounding sounds, so the recording seem to be working, but after stopping the sound the download button stay transparent. 图表随周围的声音而变化,因此录音似乎可以正常工作,但是在停止声音之后,下载按钮保持透明。
In the console I can get audioRecorder
instance, but audioRecorder.exportWAV(doneEncoding)
returns undefined
. 在控制台中,我可以获取
audioRecorder
实例,但是audioRecorder.exportWAV(doneEncoding)
返回undefined
。
> audioRecorder
< Recorder {context: AudioContext, node: ScriptProcessorNode}
> audioRecorder.exportWAV(doneEncoding)
< undefined
What am I doing wrong? 我究竟做错了什么?
I found the problem the recorder.js
uses variable in it's function. 我发现了
recorder.js
在其函数中使用变量的问题。
var WORKER_PATH = 'js/recorderjs/recorderWorker.js';
And it failed to read the file. 并且它无法读取文件。
To solve the problem I followed this answer . 为了解决这个问题,我遵循了这个答案 。
Rewrite path name in recorder.js
在
recorder.js
重写路径名
var WORKER_PATH = "<%= javascript_path 'recorderWorker.js' %>"; var WORKER_PATH =“ <%= javascript_path'recorderWorker.js'%>”;
Rename recorder.js
to recorder.js.erb
将
recorder.js
重命名为recorder.js.erb
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.