windows phone 7 通过麦克风录音,并且播放
2014-03-05 00:17
239 查看
原文:windowsphone7通过麦克风录音,并且播放
//模拟XNA的框架(凡是在wp7中应用xna的都必须先模拟此类)
publicclassXNAAsyncDispatcher:IApplicationService
{
privateDispatcherTimerframeworkDispatcherTimer;
publicXNAAsyncDispatcher(TimeSpandispatchInterval)
{
this.frameworkDispatcherTimer=newDispatcherTimer();
this.frameworkDispatcherTimer.Tick+=newEventHandler(frameworkDispatcherTimer_Tick);
this.frameworkDispatcherTimer.Interval=dispatchInterval;
}
voidIApplicationService.StartService(ApplicationServiceContextcontext)
{
this.frameworkDispatcherTimer.Start();
}
voidIApplicationService.StopService()
{
this.frameworkDispatcherTimer.Stop();
}
voidframeworkDispatcherTimer_Tick(objectsender,EventArgse)
{
FrameworkDispatcher.Update();
}
}
在App构造函数里写
this.ApplicationLifetimeObjects.Add(newXNAAsyncDispatcher(TimeSpan.FromMilliseconds(50)));
当程序激动时就开始模拟XNAGameTimer
//后代代码
usingSystem;
usingSystem.Collections.Generic;
usingSystem.Linq;
usingSystem.Net;
usingSystem.Windows;
usingSystem.Windows.Controls;
usingSystem.Windows.Documents;
usingSystem.Windows.Input;
usingSystem.Windows.Media;
usingSystem.Windows.Media.Animation;
usingSystem.Windows.Shapes;
usingMicrosoft.Phone.Controls;
usingSystem.IO;
usingMicrosoft.Xna.Framework.Audio;
namespaceWp7_录音
{
publicpartialclassMainPage:PhoneApplicationPage
{
//Constructor
publicMainPage()
{
InitializeComponent();
mic.BufferReady+=Default_BufferReady;
SoundEffect.MasterVolume=1.0f;
}
MemoryStreamms;
Microphonemic=Microphone.Default;
//Wireupaneventhandlersowecanemptythebufferwhenfull
//Crankupthevolumetomax
//Whenthebuffer'sreadyweneedtoemptyit
//We'llcopytoaMemoryStream
//WecouldpushintoIsolatedStorageetc
voidDefault_BufferReady(objectsender,EventArgse)
{
byte[]buffer=newbyte[1024];
intbytesRead=0;
while((bytesRead=mic.GetData(buffer,0,buffer.Length))>0)
ms.Write(buffer,0,bytesRead);
}
//Theuserwantstostartrecording.Ifwe'vealreadymade
//arecording,closethatMemoryStreamandcreateanewone.
//Startrecordingonthedefaultdevice.
privatevoidstart_Click(objectsender,RoutedEventArgse)
{
if(ms!=null)
ms.Close();
ms=newMemoryStream();
mic.Start();
}
//Theuserwantstostoprecording.Checksthemicrophone
//isstopped.ResettheMemoryStreamposition.
//Playbacktherecording.Pitchisbasedonslidervalue
privatevoidstop_Click(objectsender,RoutedEventArgse)
{
if(mic.State!=MicrophoneState.Stopped)
mic.Stop();
ms.Position=0;
SoundEffectse=newSoundEffect(ms.ToArray(),mic.SampleRate,AudioChannels.Mono);
//se.Play(1.0f,(float)slider1.Value,0.0f);
se.Play();
}
}
}
本实例UI就两个Button一个start一个stop,还有一个滑动条Silder.
{
privateDispatcherTimerframeworkDispatcherTimer;
publicXNAAsyncDispatcher(TimeSpandispatchInterval)
{
this.frameworkDispatcherTimer=newDispatcherTimer();
this.frameworkDispatcherTimer.Tick+=newEventHandler(frameworkDispatcherTimer_Tick);
this.frameworkDispatcherTimer.Interval=dispatchInterval;
}
voidIApplicationService.StartService(ApplicationServiceContextcontext)
{
this.frameworkDispatcherTimer.Start();
}
voidIApplicationService.StopService()
{
this.frameworkDispatcherTimer.Stop();
}
voidframeworkDispatcherTimer_Tick(objectsender,EventArgse)
{
FrameworkDispatcher.Update();
}
}
this.ApplicationLifetimeObjects.Add(newXNAAsyncDispatcher(TimeSpan.FromMilliseconds(50)));
当程序激动时就开始模拟XNAGameTimer
//后代代码
usingSystem;
usingSystem.Collections.Generic;
usingSystem.Linq;
usingSystem.Net;
usingSystem.Windows;
usingSystem.Windows.Controls;
usingSystem.Windows.Documents;
usingSystem.Windows.Input;
usingSystem.Windows.Media;
usingSystem.Windows.Media.Animation;
usingSystem.Windows.Shapes;
usingMicrosoft.Phone.Controls;
usingSystem.IO;
usingMicrosoft.Xna.Framework.Audio;
namespaceWp7_录音
{
publicpartialclassMainPage:PhoneApplicationPage
{
//Constructor
publicMainPage()
{
InitializeComponent();
mic.BufferReady+=Default_BufferReady;
SoundEffect.MasterVolume=1.0f;
}
MemoryStreamms;
Microphonemic=Microphone.Default;
//Wireupaneventhandlersowecanemptythebufferwhenfull
//Crankupthevolumetomax
//Whenthebuffer'sreadyweneedtoemptyit
//We'llcopytoaMemoryStream
//WecouldpushintoIsolatedStorageetc
voidDefault_BufferReady(objectsender,EventArgse)
{
byte[]buffer=newbyte[1024];
intbytesRead=0;
while((bytesRead=mic.GetData(buffer,0,buffer.Length))>0)
ms.Write(buffer,0,bytesRead);
}
//Theuserwantstostartrecording.Ifwe'vealreadymade
//arecording,closethatMemoryStreamandcreateanewone.
//Startrecordingonthedefaultdevice.
privatevoidstart_Click(objectsender,RoutedEventArgse)
{
if(ms!=null)
ms.Close();
ms=newMemoryStream();
mic.Start();
}
//Theuserwantstostoprecording.Checksthemicrophone
//isstopped.ResettheMemoryStreamposition.
//Playbacktherecording.Pitchisbasedonslidervalue
privatevoidstop_Click(objectsender,RoutedEventArgse)
{
if(mic.State!=MicrophoneState.Stopped)
mic.Stop();
ms.Position=0;
SoundEffectse=newSoundEffect(ms.ToArray(),mic.SampleRate,AudioChannels.Mono);
//se.Play(1.0f,(float)slider1.Value,0.0f);
se.Play();
}
}
}
本实例UI就两个Button一个start一个stop,还有一个滑动条Silder.
相关文章推荐
- windows phone 7 通过麦克风录音,并且播放
- 媒体播放组件编写完毕并且通过了初步的测试
- 通过网络发送和播放麦克风的声音
- VISTA或WIN7下使用立体声混音作为录音来源时,如何通过编程方式去除或加入麦克风的输入
- android开发(18) 调用手机的麦克风录音,并播放。
- Windows phone开发——通过sliverlight开发应用,关于播放背景音乐的问题
- iOS 播放视频进行滑动获取每一帧图片并且通过UIImageView展示出来
- XNA 通过图片播放动画,Windows Phone 游戏开发
- 【iOS录音与播放】实现利用音频队列,通过缓存进行对声音的采集与播放
- VISTA或WIN7下使用立体声混音作为录音来源时,如何通过编程方式去除或加入麦克风的输入
- Windows7下如何同步播放通过麦克等设备输入进来的声音————windows7侦听麦克风
- 【iOS录音与播放】实现利用音频队列,通过缓存进行对声音的采集与播放
- android开发(18) 调用手机的麦克风录音,并播放。
- android开发(18) 调用手机的麦克风录音,并播放。
- VISTA或WIN7下使用立体声混音作为录音来源时,如何通过编程方式去除或加入麦克风的输入
- 【iOS录音与播放】实现利用音频队列,通过缓存进行对声音的采集与播放
- 调用麦克风录音及播放
- 关于调整“录音”麦克风音量而不是“播放”中麦克风音量的问题
- 使用C#实现通过网络发送和播放麦克风的声音
- python 通过麦克风录音 生成wav文件