private void Initialize() { InitializeComponent(); recordButton = ApplicationBar.Buttons[0] as ApplicationBarIconButton; playButton = ApplicationBar.Buttons[1] as ApplicationBarIconButton; saveButton = ApplicationBar.Buttons[2] as ApplicationBarIconButton; stream = new MemoryStream(); microphone = Microphone.Default; soundIsPlaying = false; DispatcherTimer dt = new DispatcherTimer(); dt.Interval = TimeSpan.FromMilliseconds(33); dt.Tick += new EventHandler(dt_Tick); dt.Start(); microphone.BufferReady += new EventHandler<EventArgs>(microphone_BufferReady); blankImage = new BitmapImage(new Uri("Images/blank.png", UriKind.RelativeOrAbsolute)); microphoneImage = new BitmapImage(new Uri("Images/microphone.png", UriKind.RelativeOrAbsolute)); speakerImage = new BitmapImage(new Uri("Images/speaker.png", UriKind.RelativeOrAbsolute)); }
/// <summary> /// Initializes new instance of WitMic /// </summary> /// <param name="witPipedStream">Stream to write audio to</param> /// <param name="detectSpeechStop">Voice activity detection feature</param> public WitMic(WitPipedStream witPipedStream, bool detectSpeechStop) { this.witPipedStream = witPipedStream; this.detectSpeechStop = detectSpeechStop; microphone = Microphone.Default; if (microphone == null) { WitLog.Log("Did you enabled ID_CAP_MICROPHONE in WMAppManifest.xml?"); return; } witDetectTalking = new WitVadWrapper(8.0, 16000, 60); microphone.BufferDuration = TimeSpan.FromMilliseconds(100); speech = new byte[microphone.GetSampleSizeInBytes(microphone.BufferDuration)]; microphone.BufferReady += microphone_BufferReady; updateTimer = new DispatcherTimer() { Interval = TimeSpan.FromMilliseconds(1) }; updateTimer.Tick += (s, e) => { FrameworkDispatcher.Update(); }; }
/// <summary> /// Initializes a new instance of the <see cref="PhoneRecorder" /> class. /// </summary> /// <param name="microphone">The microphone.</param> public PhoneRecorder(Microphone microphone) { _mic = microphone; var timer = new DispatcherTimer {Interval = TimeSpan.FromMilliseconds(33)}; timer.Tick += timer_Tick; timer.Start(); _mic.BufferReady += microphone_BufferReady; }
public NewButtonPage() { InitializeComponent(); // Create new Microphone and set event handler buttonMic = Microphone.Default; buttonMic.BufferReady += OnMicrophoneBufferReady; buttonPlayback = new DynamicSoundEffectInstance(buttonMic.SampleRate, AudioChannels.Mono); }
byte[] msBuffer; //读取数据的缓冲区 public RecPage() { InitializeComponent(); // Microphone.Default静态属性获得默认麦克风的引用 myMicrophone = Microphone.Default; // myMicrophone.BufferDuration = TimeSpan.FromMilliseconds(1000); msBuffer = new byte[myMicrophone.GetSampleSizeInBytes(myMicrophone.BufferDuration)]; //FrameworkDispatcher.Update(); }
// コンストラクター public MainPage() { InitializeComponent(); microphone = Microphone.Default; microphone.BufferReady += OnMicrophoneBufferReady; playback = new DynamicSoundEffectInstance(microphone.SampleRate, AudioChannels.Mono); playback.BufferNeeded += OnPlaybackBufferNeeded; }
public XnaMicrophone() { this.microphone = Microphone.Default; this.timer = new DispatcherTimer() { Interval = TimeSpan.FromMilliseconds(50) }; this.timer.Tick += (s, e) => FrameworkDispatcher.Update(); }
public UDPAudioSink(bool ALaw) { _Sending = false; ALAW = ALaw; dt = new DispatcherTimer(); microphone = Microphone.Default; stream = new MemoryStream(); FrameworkDispatcher.Update(); microphone.BufferReady += new EventHandler<EventArgs>(microphone_BufferReady); }
public NetworkTestPageViewModel() { _Sending = false; microphone = Microphone.Default; stream = new MemoryStream(); InputBytes = new ObservableCollection<ByteHolder>(); G711Bytes = new ObservableCollection<ByteHolder>(); StartTimer(); microphone.BufferReady += new EventHandler<EventArgs>(microphone_BufferReady); }
public MicHelper() { //Setup mic mic = Microphone.Default; //Setup timers recordingTimer = new DispatcherTimer(); recordingTimer.Interval = TimeSpan.FromSeconds(Utils.maxRecordingDuration); recordingTimer.Tick += new EventHandler(recordingTimer_Tick); playbackTimer = new DispatcherTimer(); playbackTimer.Tick += new EventHandler(playbackTimer_Tick); }
public XnaMicrophone() { this.microphone = Microphone.Default; this.microphone.BufferReady += microphone_BufferReady; this.Start = new RelayCommand<int>( (rate) => this.microphone.Start(), (rate) => this.SupportedSampleRates.Contains(rate) && this.microphone != null && this.microphone.State == MicrophoneState.Stopped); this.Stop = new Command( () => this.microphone.Stop(), () => this.microphone != null && this.microphone.State == MicrophoneState.Started); }
/// <summary> /// Creates new instance of the AudioRecorder class. /// </summary> public AudioRecorder() { this.microphone = Microphone.Default; this.microphone.BufferDuration = TimeSpan.FromMilliseconds(500); this.buffer = new byte[microphone.GetSampleSizeInBytes(this.microphone.BufferDuration)]; this.microphone.BufferReady += new EventHandler<EventArgs>(MicrophoneBufferReady); this.InitializeXnaGameLoop(); // microphone requires special XNA initialization to work InitializeComponent(); }
public override void Initialize(AudioCaptureInitializeArgs captureArgs) { Microphone = Microphone.Default; Microphone.BufferDuration = TimeSpan.FromMilliseconds(100); // 100 minimum Microphone.BufferReady += Microphone_BufferReady; Resampler = new Resampler(DesiredClockRate / 16000); RunOnUIThread(() => { XnaTimer = new DispatcherTimer(); XnaTimer.Interval = TimeSpan.FromMilliseconds(50); XnaTimer.Tick += delegate { try { FrameworkDispatcher.Update(); } catch { } }; XnaTimer.Start(); }); }
public Recorder() { //Microphone config _microphone = Microphone.Default; _microphone.BufferDuration = TimeSpan.FromMilliseconds(100); _duration = _microphone.BufferDuration; numBytes = _microphone.GetSampleSizeInBytes(_microphone.BufferDuration); TimeSpan sample = TimeSpan.FromSeconds(1.0 / _microphone.SampleRate); int numBytesPerSample = _microphone.GetSampleSizeInBytes(sample); _buffer = new byte[numBytes]; _microphone.BufferReady += new EventHandler<EventArgs>(MicrophoneBufferReady); stream = new MemoryStream(); totalNumBytes = 0; }
public Game1() { graphics = new GraphicsDeviceManager(this); Content.RootDirectory = "Content"; // Frame rate is 30 fps by default for Windows Phone. TargetElapsedTime = TimeSpan.FromTicks(333333); // Extend battery life under lock. InactiveSleepTime = TimeSpan.FromSeconds(1); mic = Microphone.Default; mic.BufferDuration = TimeSpan.FromSeconds(1); audioBuffer = new byte[mic.GetSampleSizeInBytes(mic.BufferDuration)]; mic.BufferReady += BufferIsReady; }
public void StopCapture() { try { if (_microphone != null) { _baBuffer = new byte[0]; _microphone.BufferReady -= MicrophoneBufferReady; _microphone.Stop(); _microphone = null; } } catch (Exception) { } }
public bool RecordAudio() { try { StopRequested = false; if (microphone == null) { microphone = Microphone.Default; } sampleRate = microphone.SampleRate; microphone.BufferDuration = TimeSpan.FromMilliseconds(100); buffer = new byte[microphone.GetSampleSizeInBytes(microphone.BufferDuration)]; microphone.BufferReady += new EventHandler<EventArgs>(Microphone_BufferReady); stream = new MemoryStream(1048576); stream.SetLength(0); WriteWavHeader(microphone.SampleRate); dispatcherTimer = new System.Windows.Threading.DispatcherTimer(); dispatcherTimer.Interval = TimeSpan.FromMilliseconds(33); dispatcherTimer.Tick += delegate { try { Microsoft.Xna.Framework.FrameworkDispatcher.Update(); } catch (System.Exception ex) { System.Diagnostics.Debug.WriteLine("FrameworkDispatcher :" + ex.Message); } }; dispatcherTimer.Start(); Microsoft.Xna.Framework.FrameworkDispatcher.Update(); microphone.Start(); System.Diagnostics.Debug.WriteLine("Started Recording"); return true; } catch (System.Exception ex) { System.Diagnostics.Debug.WriteLine("RecordAudio :" + ex.Message); return false; } }
public void StartCapture() { try { if (_microphone == null) { _microphone = Microphone.Default; _microphone.BufferDuration = TimeSpan.FromMilliseconds(100); var sampleSize = _microphone.GetSampleSizeInBytes(_microphone.BufferDuration); _baBuffer = new byte[sampleSize]; _microphone.BufferReady += MicrophoneBufferReady; _microphone.Start(); } } catch (Exception) { } }
public MicRecorder() { worker.WorkerReportsProgress = true; worker.DoWork += new DoWorkEventHandler(worker_DoWork); _microphone = Microphone.Default; /* * The duration of the capture buffer must be between 100ms and 1000ms. Additionally, the capture buffer must be 10ms aligned (BufferDuration % 10 == 0). * Silverlight applications must ensure that FrameworkDispatcher.Update is called regularly in order for "fire and forget" sounds to work correctly. * BufferDuration throws an InvalidOperationException if FrameworkDispatcher.Update has not been called at least once before making this call. * For more information, see Enable XNA Framework Events in Windows Phone Applications. */ _microphone.BufferDuration = TimeSpan.FromMilliseconds(100); _duration = _microphone.BufferDuration; _bufferSize = _microphone.GetSampleSizeInBytes(_microphone.BufferDuration); _microphone.BufferReady += new EventHandler<EventArgs>(MicrophoneBufferReady); }
private MicrophoneButton(Microphone microphone) { FrameworkDispatcher.Update(); var minSupportedBufferDurationMs = 100; var duration = TimeSpan.FromMilliseconds(minSupportedBufferDurationMs); Microphone = microphone; Microphone.BufferDuration = duration; Buffer = new byte[Microphone.GetSampleSizeInBytes(duration)]; Buffer2D = new Color[TexWidth * byte.MaxValue]; Texture2D = Texture2D ?? Program.Renderer.LeaseFor<Gray, byte>(TexWidth, byte.MaxValue); Texture2D.SetData(Buffer2D); Microphone.BufferReady += OnBufferReady; Microphone.Start(); }
public MainPageViewModel() { _Sending = false; microphone = Microphone.Default; stream = new MemoryStream(); // Timer to simulate the XNA Game Studio game loop (Microphone is from XNA Game Studio) DispatcherTimer dt = new DispatcherTimer(); dt.Interval = TimeSpan.FromMilliseconds(50); dt.Tick += delegate { try { FrameworkDispatcher.Update(); } catch { } }; dt.Start(); microphone.BufferReady += new EventHandler<EventArgs>(microphone_BufferReady); }
public Clapper() { // for pumping XNA framework events t = new Timer() { Interval = 50, }; t.Tick += new EventHandler(t_Tick); UpperThreshold = 3000; LowerThreshold = 800; state = ClapperState.WaitLow; eventWatch = new Stopwatch(); window = new Queue<short>(); m = Microphone.Default; buffer = new byte[m.GetSampleSizeInBytes(TimeSpan.FromMilliseconds(100))]; m.BufferReady += new EventHandler<EventArgs>(m_BufferReady); }
public MemoRecorderViewModel() { try { // Create new Microphone and set event handler _microphone = Microphone.Default; _microphone.BufferReady += OnMicrophoneBufferReady; _timer = new DispatcherTimer(); _timer.Tick += new EventHandler(OnTimerTick); _timer.Interval = TimeSpan.FromSeconds(3); _statusTimer = new DispatcherTimer(); _statusTimer.Tick += new EventHandler(OnStatusTimerTick); _statusTimer.Interval = TimeSpan.FromMilliseconds(500); CreateTime = DateTime.Now; } catch { // Remove exception on ui designer } }
public MainPage() { InitializeComponent(); // Create new Microphone and set event handler microphone = Microphone.Default; microphone.BufferReady += OnMicrophoneBufferReady; // Create new DynamicSoundEffectInstace for playback playback = new DynamicSoundEffectInstance(microphone.SampleRate, AudioChannels.Mono); playback.BufferNeeded += OnPlaybackBufferNeeded; // Enumerate existing memo waveform files in isolated storage using (IsolatedStorageFile storage = IsolatedStorageFile.GetUserStoreForApplication()) { // Show filenames with most recent first string[] filenames = storage.GetFileNames(); Array.Sort(filenames); Array.Reverse(filenames); foreach (string filename in filenames) { using (IsolatedStorageFileStream stream = storage.OpenFile(filename, FileMode.Open, FileAccess.Read)) { TimeSpan duration = microphone.GetSampleDuration((int)stream.Length); MemoInfo memoInfo = new MemoInfo(filename, stream.Length, duration); memoFiles.Add(memoInfo); } } } // Set memo collection to ListBox memosListBox.ItemsSource = memoFiles; // Set-up record button recordButton.DataContext = spaceTime; UpdateRecordButton(false); }
/// <summary> /// Stops recording /// </summary> private void StopRecording() { this.microphone.Stop(); this.microphone.BufferReady -= MicrophoneBufferReady; this.microphone = null; btnStartStop.Content = RecordingStartCaption; // check there is some data this.btnTake.IsEnabled = true; }
/// <summary> /// Starts recording, data is stored in memory /// </summary> private void StartRecording() { this.microphone = Microphone.Default; this.microphone.BufferDuration = TimeSpan.FromMilliseconds(500); this.btnTake.IsEnabled = false; this.btnStartStop.Content = RecordingStopCaption; this.buffer = new byte[microphone.GetSampleSizeInBytes(this.microphone.BufferDuration)]; this.microphone.BufferReady += new EventHandler<EventArgs>(MicrophoneBufferReady); this.memoryStream = new MemoryStream(); this.WriteWavHeader(this.memoryStream, this.microphone.SampleRate); this.duration = new TimeSpan(0); this.microphone.Start(); }
/// <summary> /// Stops recording /// </summary> public void stopRecording() { if (this.recorder != null) { if (this.state == PlayerState_Running) { try { this.recorder.Stop(); this.recorder.BufferReady -= recorderBufferReady; this.recorder = null; SaveAudioClipToLocalStorage(); this.FinalizeXnaGameLoop(); this.SetState(PlayerState_Stopped); } catch (Exception) { //TODO } } } }
/// <summary> /// Starts recording, data is stored in memory /// </summary> /// <param name="filePath"></param> public void startRecording(string filePath) { if (this.player != null) { InvokeCallback(MediaError, MediaErrorPlayModeSet, false); } else if (this.recorder == null) { try { this.audioFile = filePath; this.InitializeXnaGameLoop(); this.recorder = Microphone.Default; this.recorder.BufferDuration = TimeSpan.FromMilliseconds(500); this.buffer = new byte[recorder.GetSampleSizeInBytes(this.recorder.BufferDuration)]; this.recorder.BufferReady += new EventHandler<EventArgs>(recorderBufferReady); MemoryStream stream = new MemoryStream(); this.memoryStream = stream; int numBits = 16; int numBytes = numBits / 8; // inline version from AudioFormatsHelper stream.Write(System.Text.Encoding.UTF8.GetBytes("RIFF"), 0, 4); stream.Write(BitConverter.GetBytes(0), 0, 4); stream.Write(System.Text.Encoding.UTF8.GetBytes("WAVE"), 0, 4); stream.Write(System.Text.Encoding.UTF8.GetBytes("fmt "), 0, 4); stream.Write(BitConverter.GetBytes(16), 0, 4); stream.Write(BitConverter.GetBytes((short)1), 0, 2); stream.Write(BitConverter.GetBytes((short)1), 0, 2); stream.Write(BitConverter.GetBytes(this.recorder.SampleRate), 0, 4); stream.Write(BitConverter.GetBytes(this.recorder.SampleRate * numBytes), 0, 4); stream.Write(BitConverter.GetBytes((short)(numBytes)), 0, 2); stream.Write(BitConverter.GetBytes((short)(numBits)), 0, 2); stream.Write(System.Text.Encoding.UTF8.GetBytes("data"), 0, 4); stream.Write(BitConverter.GetBytes(0), 0, 4); this.recorder.Start(); FrameworkDispatcher.Update(); this.SetState(PlayerState_Running); } catch (Exception) { InvokeCallback(MediaError, MediaErrorStartingRecording, false); //this.handler.InvokeCustomScript(new ScriptCallback(CallbackFunction, this.id, MediaError, MediaErrorStartingRecording),false); } } else { InvokeCallback(MediaError, MediaErrorAlreadyRecording, false); //this.handler.InvokeCustomScript(new ScriptCallback(CallbackFunction, this.id, MediaError, MediaErrorAlreadyRecording),false); } }
/// <summary> /// Destroys player and stop audio playing or recording /// </summary> public void Dispose() { if (this.player != null) { this.stopPlaying(); this.player = null; } if (this.recorder != null) { this.stopRecording(); this.recorder = null; } this.FinalizeXnaGameLoop(); }
/// <summary> /// Starts recording, data is stored in memory /// </summary> /// <param name="filePath"></param> public void startRecording(string filePath) { if (this.player != null) { InvokeCallback(MediaError, MediaErrorPlayModeSet, false); } else if (this.recorder == null) { try { this.audioFile = filePath; this.InitializeXnaGameLoop(); this.recorder = Microphone.Default; this.recorder.BufferDuration = TimeSpan.FromMilliseconds(500); this.buffer = new byte[recorder.GetSampleSizeInBytes(this.recorder.BufferDuration)]; this.recorder.BufferReady += new EventHandler<EventArgs>(recorderBufferReady); this.memoryStream = new MemoryStream(); this.memoryStream.InitializeWavStream(this.recorder.SampleRate); this.recorder.Start(); FrameworkDispatcher.Update(); this.SetState(PlayerState_Running); } catch (Exception) { InvokeCallback(MediaError, MediaErrorStartingRecording, false); //this.handler.InvokeCustomScript(new ScriptCallback(CallbackFunction, this.id, MediaError, MediaErrorStartingRecording),false); } } else { InvokeCallback(MediaError, MediaErrorAlreadyRecording, false); //this.handler.InvokeCustomScript(new ScriptCallback(CallbackFunction, this.id, MediaError, MediaErrorAlreadyRecording),false); } }