2012-07-24 159 views
0

我需要這個窗口記錄來自麥克風的音頻: XAML:如何錄製音頻和播放C#

<Window x:Class="Mesius_Leitner_Professional.Record" 
     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
     Title="Record" Height="308" Width="378"> 
    <Grid> 
     <Button Content="start" Height="23" HorizontalAlignment="Left" Margin="43,132,0,0" Name="button1" VerticalAlignment="Top" Width="75" /> 
     <Button Content="stop'n save" IsEnabled="False" Height="23" HorizontalAlignment="Right" Margin="0,132,157,0" Name="button2" VerticalAlignment="Top" Width="75" /> 
     <Button Content="play" Height="23" IsEnabled="false" HorizontalAlignment="Left" Margin="205,132,0,0" Name="button3" VerticalAlignment="Top" Width="75" /> 
    </Grid> 
</Window> 

和後面的代碼:

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using System.Windows; 
using System.Windows.Controls; 
using System.Windows.Data; 
using System.Windows.Documents; 
using System.Windows.Input; 
using System.Windows.Media; 
using System.Windows.Media.Imaging; 
using System.Windows.Shapes; 

namespace Mesius_Leitner_Professional 
{ 
    /// <summary> 
    /// Interaction logic for Record.xaml 
    /// </summary> 
    public partial class Record : Window 
    { 
     public Record() 
     { 
      InitializeComponent(); 
     } 
    } 
} 

沒有任何標準庫或我可以使用一些簡單的命令來記錄一些附加的類?

+3

已經被問。 退房[http://stackoverflow.com/questions/3694274/how-do-i-record-audio-with-c-wpf][1] [1]:HTTP:// stackoverflow.com/questions/3694274/how-do-i-record-audio-with-c-wpf – 2012-07-24 16:10:10

回答

0

可以使用WINMM.DLL

[DllImport("winmm.dll", EntryPoint = "mciSendStringA", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)] 
    private static extern int mciSendString(string lpstrCommand, string lpstrReturnString, int uReturnLength, int hwndCallback); 


mciSendString("open new Type waveaudio Alias recsound", "", 0, 0); 
     mciSendString("record recsound", "", 0, 0); 

string Resualt = @"...\Desktop\Test\test.wav"; 

     mciSendString("save recsound " + Resualt, "", 0, 0); 
     mciSendString("close recsound ", "", 0, 0); 

我希望它可以幫助你