如何从浏览器捕获音频并将其保存在服务器上?

发布于 2024-12-11 16:06:40 字数 437 浏览 2 评论 0原文

我目前正在开发一个项目 - 一个在线教育系统,我需要让学生能够在 30 秒的音频剪辑中介绍自己。

我需要用 Adob​​e Flash 来实现它。问题是我不知道 Flash + Red5 二人组如何协同工作。网上没有太多有用的资源,至少对我来说是这样,因为我是 Flash 的初学者。 (我主要做 PHP 的事情。)

1) 当你连接到服务器时,如何让它从 flash 客户端录制音频?

2) 30秒后,如何停止录制并将文件保存到服务器上的特定文件夹中?

3) 如何将此文件移动到服务器的 HTTP 文件夹,以便之后可以从主页访问它?

请注意,我是 flash 和 Red5 的初学者,所以我真的需要你们的详细解释。

多谢!

I'm currently working on a project - an online education system, and I need to make it possible for studs to introduce themselves in a 30 sec audioclip.

I need to implement it with Adobe Flash. The problem is that I have no idea how the Flash + Red5 duo work together. There aren't that many helpful recourses online, at least for me since I'm a beginner at Flash. (I do mostly PHP stuff.)

1) When you connect to the server, how do you make it record audio from flash client?

2) After 30 secs, how do you stop recording and save file in a specific folder on a server?

3) How do I move this file to the server's HTTP folder, so that I could access it from homepage after that?

Please note I'm a beginner at flash and Red5, so I really need detailed explonation from you guys.

Thanks a lot!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

仲春光 2024-12-18 16:06:40

我会尽力把答案说清楚。

1) 当你连接到服务器时,如何让它从flash客户端录制音频?

首先,您需要了解服务器和客户端之间的连接使用的协议,例如 RTMP。因此,在服务器端,我们需要设置我们的地址,如rtmp://127.0.0.1/demoServer(在red5 demoServer中是您的应用程序名称)。接下来在Flash端,我们可以通过 连接服务器NetConnection

    import flash.net.NetConnection;
    public var nc:NetConnection;
    nc = new NetConnection();
    nc.connect("rtmp://127.0.0.1/demoServer");

我可以肯定地告诉你,80%的工作都在Flash客户端。为了捕获语音,我们需要设置 麦克风

    import flash.media.Microphone;
    public var mic:Microphone;
    mic = Microphone.getMicrophone();

之后我们需要一个管道来传输从麦克风捕获的语音。幸运的是,我们有 NetStream

    import flash.net.NetStream;
    private var stream:NetStream;
    var sm:NetStream=new NetStream(nc);
    stream.attachAudio(mic);

连接就像建立一座桥梁,以便流可以将客户端的内容传输到服务器。好的,我们需要做的最后一件事是 publish

    stream.publish("some name","record");

现在,您可以在服务器端看到一个名为some name的.flv文件。如果您打开了麦克风,该文件会变得更大。

2) 30秒后,如何停止录制并将文件保存到服务器上的特定文件夹中?

创建一个从录制时开始的 30 秒计时器。超时时关闭流:

    import flash.utils.Timer;
    t = new Timer(1000, 30);
    t.addEventListener(TimerEvent.TIMER_COMPLETE, timerComplete);
    private function timerComplete(event:TimerEvent):void{
      //close the stream
      stream.close();
      mic.setSilenceLevel(0);
    }

默认情况下,red5 会将文件保存在 \webapps\dictRed5Server\streams 中。如果您想更改此设置,请查看此指南

3) 如何将此文件移动到服务器的 HTTP 文件夹,以便之后可以从主页访问它?

Red5可以与apache tomcat一起工作,您可以使用flv播放器来播放这些记录。

希望以上的片段能够对您有所帮助。我建议你可以安装red5并运行一些演示,然后google一下你不明白的内容。

I'll try my best to make the answer clearly.

1) When you connect to the server, how do you make it record audio from flash client?

First of all, you need to know the connection between server and client used protocol like RTMP. So in the server side, we need to setup our address like rtmp://127.0.0.1/demoServer(in red5 demoServer is your app name). Next in the Flash side, we can connect server by NetConnection:

    import flash.net.NetConnection;
    public var nc:NetConnection;
    nc = new NetConnection();
    nc.connect("rtmp://127.0.0.1/demoServer");

I could definitely tell you, the 80% work are in the Flash-Client side. In order to capture voice, we need setup our Microphone:

    import flash.media.Microphone;
    public var mic:Microphone;
    mic = Microphone.getMicrophone();

After that we need a pipe to transport voice captured form microphone. Fortunately we have NetStream:

    import flash.net.NetStream;
    private var stream:NetStream;
    var sm:NetStream=new NetStream(nc);
    stream.attachAudio(mic);

The connection just like building a bridge so that stream can carry stuff form client to server. OK, the last thing wo need to do is publish:

    stream.publish("some name","record");

Now, you can see a .flv file named some name in the server side. This file will get bigger if you have opened microphone.

2) After 30 secs, how do you stop recording and save file in a specific folder on a server?

Create a 30 secs timer that begins at recording. Closing the stream When time out:

    import flash.utils.Timer;
    t = new Timer(1000, 30);
    t.addEventListener(TimerEvent.TIMER_COMPLETE, timerComplete);
    private function timerComplete(event:TimerEvent):void{
      //close the stream
      stream.close();
      mic.setSilenceLevel(0);
    }

By default, red5 will save file in \webapps\dictRed5Server\streams. If you want to change this, check this guide.

3) How do I move this file to the server's HTTP folder, so that I could access it from homepage after that?

Red5 can work together with apache tomcat and you can use a flv player to play those records.

I hope above snippets can help you. I suggest to you that can install red5 and run some demos and google what you do not understand.

谢绝鈎搭 2024-12-18 16:06:40

伙计,好的一点是你知道所有的关键字 - 特别是 red5。不好的部分是您需要进行大量阅读才能配置并使其正常工作。

最好的部分是你会为自己感到高兴和自豪。 。一旦你完成它。 。你不知道。

继续前进。请记住发回您的发现。

Dude the good part is that you know all the keywords - red5 especially. The bad part is that you need to do alot of reading to configure and make it working.

The best part is that you will be so happy and proud of yourself . . Once you complete it . . You have no idea.

Keep going. Remember to post back your findings.

人疚 2024-12-18 16:06:40

如果您可以以 Flash Player 10.1 或更高版本为目标,那么您也许可以完全避免 FMS 或 Red5。您可以访问原始 PCM 数据,然后将其上传到为您存储的脚本。您的 SWF 或脚本必须将此数据保存为声音文件,例如 WAV 或 MP3。

查看 Adob​​e 开发人员连接上的这篇文章,它可以完成您想要的大部分功能,但无需上传:http://www.adobe.com/devnet/air/flex/articles/using_mic_api.html

If you can target Flash Player 10.1 or above then you may be able to avoid FMS or Red5 altogether. You can access the raw PCM data and then upload this to a script that stores it for you. Either your SWF or the script will have to save this data as a sound file, for example WAV or MP3.

Check out this article on the Adobe Developer Connection, it does most of what you want minus the uploading bit: http://www.adobe.com/devnet/air/flex/articles/using_mic_api.html

絕版丫頭 2024-12-18 16:06:40

如上所述,如果您的目标是 FP 10.1 或更高版本,则可以避免拥有特殊的服务器,而只需使用您习惯的后端即可。

在AS3中,你需要做的就是将录制的PCM数据存储在ByteArray中,然后将ByteArray发送到你的服务器;然而,如果您想压缩它以节省带宽,有大量的库可以帮助您。

我编写了一些代码片段,当您了解从麦克风抓取音频并将其存储在 ByteArray 中的基础知识时,您可能会发现它们很有用。

http://wonderfl.net/c/zE8I

我尝试使其尽可能基本,并且尽可能多地发表评论;然而,如果您需要帮助,您可以随时询问。

关于将 ByteArray 发送到服务器:

通过 as3 将 ByteArray 发送到 PHP

希望这有帮助。

As stated above if you target FP 10.1 or higher, you can avoid having to have a special server, and simply use the back-end you are used to.

In AS3 all you need to do is store the recorded PCM data in a ByteArray, and then send the ByteArray to your server; yet, if you want to compress it to save bandwidth, there are a ton of libraries out there that can help you.

I wrote a few code snippets you may find useful when it comes to understanding the basics of grabbing audio from the mic, and storing in a ByteArray.

http://wonderfl.net/c/zE8I

I tried to keep it as basic as possible, and to comment as much as I could; yet, if you need help, you can always ask.

With regard to sending a ByteArray to a server:

Sending ByteArray through as3 to PHP

Hope this helps.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文