Pergunta

I would like to capture the microphone and play it back immediately. I was looking for a solution how to use MediaCapture element under windows 8 to capture only audio data from the microphone but I only found how to capture a webcam. If somebody could tell me as well how to modify the data before playing it back that would be amazing. Please I'm dying for an answer. It doesn't matter whether the answer is in c# or c++.

Foi útil?

Solução

I wrote this for a desktop app but the same thing should work pretty much anywhere.

 private void RecordAudio()
    {
        var capture = new MediaCapture();
        var settings = new MediaCaptureInitializationSettings();
        settings.StreamingCaptureMode = StreamingCaptureMode.Audio;

        capture.InitializeAsync(settings).Completed = (info, status) =>
            {
                StorageFolder folder = KnownFolders.DocumentsLibrary;
                var op = folder.CreateFileAsync("sample.mp3", CreationCollisionOption.ReplaceExisting);

                op.Completed = (
                    i, s) =>
                    {
                        var file = i.GetResults();
                        var profile = MediaEncodingProfile.CreateMp3(AudioEncodingQuality.High);
                        capture.StartRecordToStorageFileAsync(profile, file);
                    };
            };

    }
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top