.NET中的WAMI记录器

时间:2013-01-23 01:44:13

标签: .net asp.net-mvc-3 flash voice-recording

我正在看这款闪光录音机: http://code.google.com/p/wami-recorder/

有没有人在.NET中成功实现过它(特别是MVC3 C#)?我在网站上看到的只是没有实际演示站点的PHP实现。

另外,如果有人有很好的录音选择,那就太好了。谢谢!

2 个答案:

答案 0 :(得分:0)

您需要做的就是设置recordUrl和playUrl

作为基本实现,您可以执行以下操作:

@{
    var payUrl = "http://yourdomain/recordings/recording-" + Session["recordingId"] + ".wav";
    <!-- saves the wav file to local folder called recodings using a session value to make unique file names -->
}
<script>
        function setupRecorder() {
            Wami.setup({
                id: "wami",
                onReady: setupGUI
            });
        }

        function setupGUI() {
            var gui = new Wami.GUI({
                id: "wami",
                recordUrl: "http://yourdomain/home/Save",
                playUrl: "@payUrl"
            });

            gui.setPlayEnabled(false);
        }
</script>

并在家庭控制器中添加保存操作

public ActionResult Save()
{
    Request.SaveAs(Server.MapPath("/recordings/recording-" + Session["recordingId"].ToString() + ".wav"), false);
    return Json(new {Success = true}, JsonRequestBehavior.AllowGet);
}

答案 1 :(得分:0)

将以下代码放入您的页面:

<div id="wami"></div>

以下代码背后是:

protected override void OnPreRender(EventArgs e) {
    ScriptManager.RegisterStartupScript(Page, GetType(), "setupRecorder", "setupRecorder();", true);
    base.OnPreRender(e);
}

创建一个网页,比如 RecorderPage.aspx ,将html留空并将以下内容放在后面的代码中:

private const string Path = "/App_Data/recordings";
private static readonly string FileName = string.Format("audio-{0}-{1}.wav", DateTime.Now.ToString("yyyyMMdd"), Guid.NewGuid());
private static readonly string Directory = HttpContext.Current.Server.MapPath(Path);

protected void Page_Load(object sender, EventArgs e) {
    string mapPath = HttpContext.Current.Server.MapPath(Path);
    string action = Request.QueryString["action"];
    if (!action.HasValue()) {
        return;
    }
    if (action.Equals("save")) {
        if (!System.IO.Directory.Exists(Directory)) {
            System.IO.Directory.CreateDirectory(Directory);
        }
        Request.SaveAs(Server.MapPath(Path + "/" + FileName), false);
    } else if (action.Equals("play")) {
        HttpContext.Current.Response.Clear();
        HttpContext.Current.Response.ClearContent();
        HttpContext.Current.Response.ClearHeaders();
        HttpContext.Current.Response.Buffer = true;
        HttpContext.Current.Response.BufferOutput = true;
        HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=" + FileName);
        HttpContext.Current.Response.Charset = "utf-8";
        HttpContext.Current.Response.AddHeader("Content-Type", "audio/x-wav");
        HttpContext.Current.Response.ContentType = "audio/x-wav";
        HttpContext.Current.Response.AddHeader("Pragma", "no-cache");
        Response.WriteFile(mapPath + "/" + FileName);
        HttpContext.Current.Response.Expires = -1;
        HttpContext.Current.Response.Flush();
        HttpContext.Current.Response.End();
    }
}

确保正确导入所有必需的文件(buttons.png,gui.js,recorder.js和Wami.swf)。

最后,在页面的脚本部分中包含这两个功能,根据您的配置修改recordUrlplayUrl

function setupRecorder() {
    Wami.setup({
        id: "wami",
        onReady: setupGUI
    });
}

function setupGUI() {
    var gui = new Wami.GUI({
        id: "wami",
        recordUrl: "http://localhost/RecorderPage.aspx?action=save",
        playUrl: "http://localhost/RecorderPage.aspx?action=play"
    });

    gui.setPlayEnabled(false);
}