Click here to Skip to main content
15,878,959 members
Articles / Web Development / ASP.NET

Silverlight Pronunciation Test

Rate me:
Please Sign up or sign in to vote.
5.00/5 (12 votes)
29 Apr 2012CPOL11 min read 43.7K   1.7K   15  
How to create a pronunciation test tool using Silverlight and Python
using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.IO;

namespace AudioRecorder.Audio
{
    public class MemoryAudioSink : AudioSink
    {
        // Memory sink to record into.
        private MemoryStream _stream;
        // Current format the sinks records audio in.
        private AudioFormat _format;

        public Stream BackingStream
        {
            get { return _stream; }
        }

        public AudioFormat CurrentFormat
        {
            get { return _format; }
        }

        protected override void OnCaptureStarted()
        {
            _stream = new MemoryStream(1024);
        }

        protected override void OnCaptureStopped()
        {            
        }

        protected override void OnFormatChange(AudioFormat audioFormat)
        {
            if (audioFormat.WaveFormat != WaveFormatType.Pcm)
                throw new InvalidOperationException("MemoryAudioSink supports only PCM audio format.");

            _format = audioFormat;
        }

        protected override void OnSamples(long sampleTime, long sampleDuration, byte[] sampleData)
        {
            // New audio data arrived, write them to the stream.
            _stream.Write(sampleData, 0, sampleData.Length);
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Instructor / Trainer Alura Cursos Online
Brazil Brazil

Comments and Discussions