none
[W8.1] How to get the volume when recording sound? RRS feed

  • Question

  • I record sounds and i need get volume in processing. How can i do it?

    This's my code, which run after initialization:

    void Nikki::MainPage::StartRecordVoice() {
    	String ^fileName = "voice.wav";
    	if (!m_RECORD) {
    		task<StorageFile^>(KnownFolders::VideosLibrary->CreateFileAsync(fileName, Windows::Storage::CreationCollisionOption::ReplaceExisting)).then([this](task<StorageFile^> fileTask)
    		{
    			try
    			{
    				this->m_recordStorageFile = fileTask.get();
    
    				MediaEncodingProfile^ recordProfile = nullptr;
    				recordProfile = MediaEncodingProfile::CreateWav(Windows::Media::MediaProperties::AudioEncodingQuality::Auto);
    
    				create_task(m_mediaCaptureMgr->StartRecordToStorageFileAsync(recordProfile, this->m_recordStorageFile)).then([this](task<void> recordTask)
    				{
    					try
    					{
    						recordTask.get();
    						m_RECORD = true;
    					}
    					catch (Exception ^e)
    					{
    						m_RECORD = true;
    					}
    				});
    			}
    			catch (Exception ^e)
    			{
    				m_RECORD = false;
    			}
    		});
    	}
    
    	else
    	{
    		create_task(m_mediaCaptureMgr->StopRecordAsync()).then([this](task<void>)
    		{
    			try
    			{
    				m_RECORD = false;
    			}
    			catch (Exception ^e)
    			{
    				m_RECORD = false;
    			}
    		});
    	}
    }

    What should i look to do it? 
    Wednesday, June 24, 2015 9:07 AM

Answers

  • Hello,

    Unfortunately there is no easy way to get the audio magnitude from the MediaCapture element during recording. One option would be to write a custom Media Foundation Transform (MFT) to calculate the RMS and offer the data to the UI. You could then plug the MFT into the MediaCapture by adding it as an effect.

    I hope this helps,

    James


    Windows SDK Technologies - Microsoft Developer Services - http://blogs.msdn.com/mediasdkstuff/

    • Marked as answer by AngryJack93 Saturday, June 27, 2015 6:24 AM
    Friday, June 26, 2015 6:31 PM
    Owner

All replies

  • As a friendly reminder please make sure to add the appropriate tags to the title

    of your post as per our Guide

    to posting: subject line tags.

    Unfortunately it is not clear from your post what you mean by "volume".

    Are you looking to get the magnitude of the audio during recording of the recorded material or are you trying to get the attenuation of the microphone? 

    -James


    Windows SDK Technologies - Microsoft Developer Services - http://blogs.msdn.com/mediasdkstuff/

    Wednesday, June 24, 2015 8:13 PM
    Owner
  • I'm sorry.

    First. I need to get the magnitude of the audio during recording of the recorded material.

    Wednesday, June 24, 2015 9:33 PM
  • Hello,

    Unfortunately there is no easy way to get the audio magnitude from the MediaCapture element during recording. One option would be to write a custom Media Foundation Transform (MFT) to calculate the RMS and offer the data to the UI. You could then plug the MFT into the MediaCapture by adding it as an effect.

    I hope this helps,

    James


    Windows SDK Technologies - Microsoft Developer Services - http://blogs.msdn.com/mediasdkstuff/

    • Marked as answer by AngryJack93 Saturday, June 27, 2015 6:24 AM
    Friday, June 26, 2015 6:31 PM
    Owner