Get microphone input

Hi, I’m trying to get microphone input in unreal.

I have this code that verifies that modules are correctly initialized:

bool bHasVoiceEnabled = false;
TSharedPtr<class IVoiceCapture> VoiceCapture;
if(GConfig->GetBool(TEXT("OnlineSubsystem"), TEXT("bHasVoiceEnabled"), bHasVoiceEnabled, GEngineIni) && bHasVoiceEnabled)
{
    		VoiceCapture->Start();
}

The output is:

[2017.08.21-15.32.40:669][  0]LogWindows:Error: === Critical error: ===
[2017.08.21-15.32.40:669][  0]LogWindows:Error: 
[2017.08.21-15.32.40:669][  0]LogWindows:Error: Assertion failed: IsValid() [File:C:\Program Files (x86)\Epic Games\4.14\Engine\Source\Runtime\Core\Public\Templates\SharedPointer.h] [Line: 794] 

Can someone tell me what’s wrong?
Thanks!

Assortion is a check if specific condition is meet, if not it will crash the engine and print what condition failed, in you case condition was IsValid() which is a function and it return false. Normally you should go to line in pointing to in engine source code to see whats wrong… but those one is very easy to guess, it happens in SharedPointer.h and only shered pointer you use is TSharedPtr<class IVoiceCapture> VoiceCapture; so it easy to guess that you have invalid pointer here. Even by looking on code you can clearly see you decler a pointer but you never set and and then you make function call on it and it crashes because you calling it to some thing that does not exist

you need to get voice capture first so do this:

VoiceCapture = FVoiceModule::Get().CreateVoiceCapture();
if(!VoiceCapture.IsValid()) return; //insted of return you can do something else in case of fail

Thank you very much for your answer.
Now my code is

TSharedPtr<class IVoiceCapture> VoiceCapture;
VoiceCapture = FVoiceModule::Get().CreateVoiceCapture();

if (!VoiceCapture.IsValid())
{
	UE_LOG(LogTemp, Warning, TEXT("NOT VALID 1"));
	return;
}
VoiceCapture->Start();
uint32 VoiceCaptureBytesAvailable = 0;
EVoiceCaptureState::Type CaptureState = VoiceCapture->GetCaptureState(VoiceCaptureBytesAvailable);

And the output is:

[2017.08.22-07.39.35:062][525]LogWindows:Error: === Critical error: ===
[2017.08.22-07.39.35:062][525]LogWindows:Error: 
[2017.08.22-07.39.35:062][525]LogWindows:Error: Fatal error!
[2017.08.22-07.39.35:062][525]LogWindows:Error: 
[2017.08.22-07.39.35:062][525]LogWindows:Error: Unhandled Exception: EXCEPTION_ACCESS_VIOLATION reading address 0x000000b8
[2017.08.22-07.39.35:062][525]LogWindows:Error: 
[2017.08.22-07.39.35:062][525]LogWindows:Error: UE4Editor-Engine.dll
[2017.08.22-07.39.35:062][525]LogWindows:Error: UE4Editor-UnrealEd.dll
[2017.08.22-07.39.35:062][525]LogWindows:Error: UE4Editor.exe
[2017.08.22-07.39.35:062][525]LogWindows:Error: KERNEL32.DLL
[2017.08.22-07.39.35:062][525]LogWindows:Error: ntdll.dll
[2017.08.22-07.39.35:062][525]LogWindows:Error: ntdll.dll
[2017.08.22-07.39.35:062][525]LogWindows:Error: 
[2017.08.22-07.39.35:093][525]LogExit: Executing StaticShutdownAfterError
[2017.08.22-07.39.35:096][525]LogWindows: FPlatformMisc::RequestExit(1)

Thank you for your help!

Solved, problem in config file