如何使用Javascript / PHP录制用户的声音? [关闭]

我目前正在尝试创建一个允许用户录制语音备注并将其保存到其帐户的测试站点。 使用PHP或JavaScript执行此操作的最佳方法是什么?</ p>

我希望此过程的步骤如下:</ p>

1 )用户单击录制按钮。
2)启动录制序列。</ strong>
3)停止序列。
4)命名文件并将其发送到服务器。</ p>

我的主要查询主要集中在第二步</ strong>,我需要一些机制与用户的麦克风进行交互以录制语音。 我仍然是Web开发人员的新手,我不知道如何使用JavaScript调用录音。 </ p>

在谷歌搜索时,我在StackOverflow中找到了一些解决类似问题的链接,但答案没有帮助。 许多解决方案都指向Flash,但我希望尽可能避免这种情况。 所以我的问题归结为“是否有可能使用JavaScript录制语音?如果是,怎么做?”</ p>

提前致谢。</ p>
</ div>

展开原文

原文

I am currently trying to make a test site that allows users to record voice-notes and save it to their account. What is the best way to do this using either PHP or JavaScript?

The steps that I am looking to have for this process are:

1) User clicking the record button. 2) Initiation of the recording sequence. 3) Stopping the sequence. 4) Naming of the file and sending it over to the server.

My main query is focused on the 2nd step, where I'd need some mechanism that would interact with the user's mic to record the voice. I am still new to web dev per se and I do not know how I can invoke voice recording using JavaScript.

Upon searching in Google, I found some links in StackOverflow which addressed similar issues but the answers were not helpful. A lot of solutions pointed to Flash but I would like to avoid that as much as possible. So my question does boil down to "Is it possible to record voice using JavaScript? If yes, how?"

Thanks in advance.

dongpobo6009
dongpobo6009 希望这会帮助你。slides.html5rocks.com/#speech-input
大约 8 年之前 回复
dqzd92796
dqzd92796 使用flash或html5可能重复捕获音频输入
大约 8 年之前 回复
dongluyi5123
dongluyi5123 我要投票结束这个,因为它是重复的......
大约 8 年之前 回复
douchunxian9740
douchunxian9740 感谢您的建议!我将对问题进行一些修改。
大约 8 年之前 回复
dovs36921
dovs36921 我已经投票重新开放,但问题仍然可以使用改进,主要是因为仍然没有实际问题。听起来第二步确实是你需要帮助的地方,但你没有具体的问题;提出一个将极大地帮助。如果您认为这可以在JavaScript中完成,请对谷歌进行一些研究(听起来像你做过),发布为什么它没有帮助,准确解释你想要什么,你尝试过什么,以及你在哪里卡住。你可以添加的任何东西,以帮助人们相信你一直在努力解决这个问题,这将使人们感到更加仁慈。
大约 8 年之前 回复
douguo7431
douguo7431 呵呵StackOverloadHA
大约 8 年之前 回复
dongle7882
dongle7882 我认为它是封闭的,因为海报没有展示他们自己所做的任何努力或研究。因此,很难准确地猜出问题的确切意图。
大约 8 年之前 回复
droos02800
droos02800 我不确定为什么这个问题被关闭了。由于它标记为JavaScript/HTML5,我认为它根本不含糊。用户试图询问他们如何在浏览器中录制音频。由于它也被标记为PHP,我认为下一个合乎逻辑的步骤是通过XHR将捕获的音频发送到服务器。这是WebRTC可能处理的问题。不幸的是,我认为我不能重新打开这个问题。
大约 8 年之前 回复

3个回答



HTML5 Audio API在浏览器中不受广泛支持,我认为它适用于Chrome,Firefox最近已将其添加到其夜间。 ..此阶段需要浏览器前缀,但通用API是...... </ p>

  navigator.getUserMedia({audio:true},function(stream){/ * do stuff  * /}); 
</ code> </ pre>

因此,Chrome的 webkitGetUserMedia </ code>和Firefox的 mozGetUserMedia </ code>。</ p>

您现在更一致的选择是通过浏览器插件(如Flash或Java)或创建用户需要安装的桌面客户端。</ p>

资源 关于getUserMedia感兴趣:</ p>

展开原文

原文

The HTML5 Audio API is not widely supported in browsers, I think it works in Chrome and Firefox has had it recently added to its nightlies... Browser prefixes are required at this stage but the general API is...

navigator.getUserMedia({audio: true}, function(stream) { /* do stuff */ });

So that would be webkitGetUserMedia for Chrome and mozGetUserMedia for Firefox.

Your more consistent options right now are via browser plugins such as Flash or Java or to create a desktop client that the user would need to install.

Resources of interest regarding getUserMedia:

The following question may assist you further:

tutorial on using flash or java servlet to upload microphone data from browser to server?



在HTML5录音到来之前,你真的需要将一个结合Flash和移动设备的解决方案,文件上传。 在移动设备上,文件上传屏幕通常具有音频或视频记录器,因此用户可以直接从他们的设备进行记录。 </ p>

如果设备上传文件时没有录音机,则应使用录像机,然后将视频转换为服务器上的MP3。 这就是我们在 recordmp3online.com 上执行此操作的方式。</ p>
</ div>

展开原文

原文

Until HTML5 audio recording arrives, you really need to hobble together a solution that combines Flash and on mobile devices, file upload. On mobile devices the file upload screen usually has an audio or video recorder, so users can record direct from their device.

If the device doesn't have an audio recorder on the file upload, you should use the video recorder and then convert the video to MP3 on the server. That is how we do it over it at recordmp3online.com .

You are now able to record from a microphone by creating an audio graph that connects your local MediaStream to a ScriptProcessingNode:

navigator.webkitGetUserMedia({video: true, audio: true}, function(stream) {
    var audioContext = new webkitAudioContext,
        mediaStreamSource = context.createMediaStreamSource(stream),
        processor = context.createJavaScriptNode(4096, 2, 2);

    processor.onaudioprocess = function(e) {
        // Process the audio data found in e.inputBuffer
    };

    mediaStreamSource.connect(processor);
    processor.connect(context.destination);
});

(Using Chrome vendor prefixes)

You can hook this up to Websockets or even plain XHR to send the chunks to your server, which can process it into an audio file. You'll need to convert each channel from

non-interleaved IEEE 32-bit linear PCM with a nominal range of -1 -> +1

into the format of your choice.

A similar example of recording audio, encoding it into a wav file, and saving it (all client-side) can be found here:

https://github.com/muaz-khan/WebRTC-Experiment/tree/master/RecordRTC

More details on AudioContext:

http://docs.webplatform.org/wiki/apis/webaudio/AudioContext

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐