将原始PCM转换为wav或Mp3文件并保存到隔离存储wp7 [英] Convert Raw PCM to wav or Mp3 file and save to Isolated storage wp7

查看:104
本文介绍了将原始PCM转换为wav或Mp3文件并保存到隔离存储wp7的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好我以下代码从麦克风中捕获声音并保存为原始文件,但我需要帮助将原始文件保存为wav或mp3



这是我的代码......

Hi guys i have the following code below to capture sound from a mic and save as a raw file, but i need help saving the raw file as either wav or mp3

this is my code...

public partial class IA_AudioPad : PhoneApplicationPage
    {

        private Microphone mic = Microphone.Default;
        private MemoryStream stream;
        byte[] buffer;
        double msElapsed;

        private DispatcherTimer timer = new DispatcherTimer();

        private const string ConnectionString = @"isostore:/DBs/IAssist_DB.sdf";

        public IA_AudioPad()
        {
            InitializeComponent();

            // Some necessary setup for our Microsoft.Xna.Framework.Audio.Microphone  
            mic.BufferDuration = TimeSpan.FromSeconds(1);
            buffer = new byte[mic.GetSampleSizeInBytes(mic.BufferDuration)];

            // Create the event handler.  I could have done an anonymous  
            // delegate here if I had so desired.  
            mic.BufferReady += handleBufferReady;


            timer.Interval = TimeSpan.FromMilliseconds(500);
            timer.Tick += new EventHandler(timer_Tick);
        }

        private void handleBufferReady(object sender, EventArgs e)
        {
            mic.GetData(buffer);
            stream.Write(buffer, 0, buffer.Length);
        }

        private void timer_Tick(object sender, EventArgs e)
        {
            msElapsed += 500;
            TimeSpan span = TimeSpan.FromMilliseconds(msElapsed);
            Timer.Text = String.Format("{0:d2} : {1:d2} : {2:d2}", span.Hours, span.Minutes, span.Seconds);
        }

        private void Record_Button_Click(object sender, EventArgs e)
        {
            msElapsed = 0;
            timer.Start();
            stream = new MemoryStream();
            mic.Start();
            Rec_Txt.Text = "Recording Note...";
            SetButtonStates(false, true, false);
        }

        private void Stop_Button_Click(object sender, EventArgs e)
        {
            timer.Stop();
            mic.Stop();
            Rec_Txt.Text = "Save Note";
            SetButtonStates(false, false, true);
        }

        private void Save_Btn_Click(object sender, EventArgs e)
        {
            string filename = string.Format("Media/Audio/{0}", AudPadTitle_Txt.Text);
            writeFile(stream, filename);
            AddAudpad_Det();
        }

        private void writeFile(MemoryStream s, string Filename)
        {
            using (var userStore = IsolatedStorageFile.GetUserStoreForApplication())
            {
                using (var file = userStore.OpenFile(Filename, FileMode.CreateNew))
                {
                    s.WriteTo(file);
                }
            }
        }

推荐答案

您是否尝试使用Google搜索?



这里有一个开源项目:



http://sox.sourceforge.net/ [ ^ $



这是命令行实用程序的源代码,可以在各种音频文件格式之间进行转换(包括原始到WAV和WAV到MP3) - 但不是直接从原始到MP3)。



这是一篇描述该实用程序使用的文章:



http://www.thegeekstuff。 com / 2009/05 / sound-exchange-sox-15-examples-to-manipulate-audio-files / [ ^ ]



因为它是一个开源项目,你可以下载源代码(可以编译对于Windows)并使用它所需的任何部分。



我想它是用C ++编写的 - 但是将C#程序链接到一些C ++代码(本机或托管代码)比将要更容易是自己写的。
Did you try googling?

There is an open source project here:

http://sox.sourceforge.net/[^]

That is the source for a command line utility program that converts between all sorts of audio file formats (including raw to WAV and WAV to MP3 -- but not directly from raw to MP3).

Here's an article describing the use of the utility:

http://www.thegeekstuff.com/2009/05/sound-exchange-sox-15-examples-to-manipulate-audio-files/[^]

Since it's an open source project you can download the source (which can be compiled for Windows) and use whatever part of it you need.

I imagine it's written in C++ -- but it's going to be a lot easier to link your C# program to some C++ code (native or managed) than it is going to be to write it yourself.


这篇关于将原始PCM转换为wav或Mp3文件并保存到隔离存储wp7的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆