locked
Get recorded sound representation in WinJS Application

    Question

  • Hi, there.

    I want to create Windows 8 app, using HTML and JavaScript, and want to record sound and represent real time the sound variation with a graphic. I followed this article (http://msdn.microsoft.com/en-us/library/windows/apps/hh452798.aspx) and was able to record the sound to an mp3 file. What I want to achieve, in addition, is to attach to some event, that gives me real time information about the recorder sound. Then using that data I want to analyze it, take all or some of the discrete points of the sound representation, convert them to JSON (for example) and then visualize that information. I have all the available resources unless that I cannot get real time representation. I investigated the "oMediaCapture" object (see code below), but couldn't get such functionality. Then I've tried to use stream and hope that it will propose such functionality. But then I get exception when I try to create "RandomAccessStream", following the MSDN article (http://msdn.microsoft.com/en-us/library/windows/apps/windows.storage.streams.randomaccessstream.aspx). 

    var stream = new Windows.Storage.Streams.RandomAccessStream();

    Here is my full code:

    (function InitSound() {
        var settings = initCaptureSettings();
        initMediaCapture(settings);
    })();
     
     
    function initCaptureSettings() {
        var captureInitSettings = null;
        captureInitSettings = new Windows.Media.Capture.MediaCaptureInitializationSettings();
        captureInitSettings.audioDeviceId = "";
        captureInitSettings.streamingCaptureMode = Windows.Media.Capture.StreamingCaptureMode.audio;
        captureInitSettings.realTimeModeEnabled = true;
        return captureInitSettings;
    }
     
    function initMediaCapture(captureInitSettings) {
        oMediaCapture = null;
        oMediaCapture = new Windows.Media.Capture.MediaCapture();
        oMediaCapture.initializeAsync(captureInitSettings).then(function (result) {
            createProfile();
        }, errorHandler);
    }
     
    function createProfile() {
        profile = Windows.Media.MediaProperties.MediaEncodingProfile.createMp3(Windows.Media.MediaProperties.AudioEncodingQuality.high);
    }
     
    function errorHandler(e) {
     
    }
     
    function recordSound() {
        var stream = new Windows.Storage.Streams.RandomAccessStream();
        oMediaCapture.startRecordToStreamAsync(profile, stream).then(function (result) {
                
        }, errorHandler);
        /*Windows.Storage.KnownFolders.videosLibrary.createFileAsync("checkMic.mp3", Windows.Storage.CreationCollisionOption.generateUniqueName).then(function (newFile) {
            storageFile = newFile;
            oMediaCapture.startRecordToStorageFileAsync(profile, storageFile).then(function (result) {
                
            }, errorHandler);
        });*/

    So do you see an obvious mistake or just the approach is wrong?

    Thank you in advance!

    Best regards,

    Nikolay Alipiev








    Wednesday, November 13, 2013 5:13 PM

Answers

All replies

  • You'll need to drop down to C++ and WASAPI to get the raw data to do this analysis. See theWindows Audio Session (WASAPI) sample


    --Rob

    Thursday, November 14, 2013 2:44 PM
    Owner
  • Hi, Rob.

    Thank you for the answer. I thought that WinJS will propose such a functionality, but now I will check the C++ example and will use it. I see that the sample is only in C++. Is this mean that there isn't such a functionality also for C#?

    Best regards,

    Nikolay Alipiev

    Friday, November 15, 2013 2:36 PM
  • Correct. WASAPI (like other low level media handling) is native only.

    For some uses you can interop to it from C#, but there is no direct support for this and there are some problems that cannot be avoided with the garbage collector.

    --Rob

    Friday, November 15, 2013 6:30 PM
    Owner
  • Rob, thank you very much for the clarification!!!

    Monday, November 18, 2013 7:17 AM