0

关于 windows phone 7 中的语音(音频)录制,我面临以下问题。

我正在使用 Microsoft.Xna.Framework.Audio 命名空间中可用的 Microphone 类录制声音。这是代码 -

变量声明:

private Microphone mic = Microphone.Default;
private MemoryStream stream;
private const string FILE_NAME = "recording.mp3";
byte[] buffer;

录制按钮点击代码-

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 += new EventHandler<EventArgs>(mic_BufferReady);

stream = new MemoryStream();
mic.Start();

缓冲区就绪事件代码 ----------

void mic_BufferReady(object sender, EventArgs e)
{
    mic.GetData(buffer);
    // Write buffer to stream
    stream.Write(buffer, 0, buffer.Length);  
}

按钮停止代码 -

private void btnStop_Click(object sender, RoutedEventArgs e)
{
    dt.Stop();
    btnStop.IsEnabled = false;
    btnPlayRecording.IsEnabled = true;

    mic.Stop();
    //Writing stream into Storage
     writeFile(stream);
}

private void writeFile(MemoryStream s, string name)
{
    try
    {
        using (var userStore = IsolatedStorageFile.GetUserStoreForApplication())
        {
            if (userStore.FileExists(name))
            {
                userStore.DeleteFile(name);
            }
            using (var file = userStore.OpenFile(name, FileMode.CreateNew))
            {
                s.WriteTo(file);
            }
        }
    }
    catch (Exception ee)
    {

    }
}

一旦我将流保存到隔离存储并播放它,音量非常低,质量也不好。

所以

  1. 我们可以放大音量吗?
  2. 我们可以提高比特率吗?
  3. 我们可以做 Fadin-Fadout 吗?

如果这三个在 windows phone 7 中都不可能,那么是否有任何第三方 API 可用于执行所有这些操作?

提前致谢

4

1 回答 1

0

.NET 中的放大并非易事。我发现的最佳方法是对“SoX,声音处理程序的瑞士军刀”进行外部进程调用。( http://sox.sourceforge.net/ )

我没有 Windows 7 手机——所以我不确定 SOX 是否在那里运行。

格式为 SOX -V volume_parameter inputFileName outputFileName 用于放大,所以:

“sox.exe -v 3.0 myNormalFile.wav myAmpedFile.wav”

会给你300%的放大。Sox 还允许更改比特率……不确定 Fadein/Fadeout。

我没有专门针对 Windows 7 手机的任何东西,而是直接使用 .NET/C# 代码:

string finalFileName = "myAmplifiedFile.WAV";
string tmpFileName = "tmpHoldingFile.WAV";
string soxEXE = @"C:\SOX\sox.exe";
string soxArgs = "-v 3.0 ";

/// OTHER STUFF HERE 

/*-----------------------------------------------------------
* Call the SOX utility to amplify it so it is 3 times as loud.
*-----------------------------------------------------------*/
try
{
    System.Diagnostics.Process process = new System.Diagnostics.Process();
    process.StartInfo = new System.Diagnostics.ProcessStartInfo();
    process.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
    process.StartInfo.FileName = soxEXE;
    process.StartInfo.Arguments = string.Format("{0} {1} {2}",
                             soxArgs, tmpFileName, finalFileName);
    process.Start();
    process.WaitForExit();
    int exitCode = process.ExitCode;
}
catch (Exception ex)
{
    string err = ex.Message;
    return false;
}
/*-------------------------------------------------------------
 * OK, now we play it using SoundPlayer
 *-------------------------------------------------------------*/
try
{
    SoundPlayer simpleSound = new SoundPlayer(@finalFileName);
    simpleSound.PlaySync();
    FileInfo readFile = new FileInfo(finalFileName);
    string finalDestination = finalDirectory + "/" + readFile.Name;
    readFile.MoveTo(finalDestination);
}
catch (Exception e)
{
    string errmsg = e.Message;
    return false;
}
finalFileName = "";
tmpFileName = "";
spVoice = null;
于 2013-05-06T13:56:51.473 回答