# IVoiceCapture Get data return 0 on android , while capturing state is OK

**URL:** <https://forums.unrealengine.com/t/ivoicecapture-get-data-return-0-on-android-while-capturing-state-is-ok/428119>\
**Category:** Audio\
**Tags:** error, microphone, voice, unreal-engine, bug-report, CPP, question\
**Created:** [June 25, 2018, 11:00pm UTC](https://forums.unrealengine.com/t/ivoicecapture-get-data-return-0-on-android-while-capturing-state-is-ok/428119 "2018-06-25T23:00:55Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Omar\_Vector](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Omar\_Vector](https://forums.unrealengine.com/u/Omar_Vector)\
**Post date:** [June 25, 2018, 11:00pm UTC](https://forums.unrealengine.com/t/ivoicecapture-get-data-return-0-on-android-while-capturing-state-is-ok/428119/1 "2018-06-25T23:00:55Z")

</div>

With regard to this Bug [UE-58340](https://issues.unrealengine.com/issue/UE-58340) , not sure if its related or not,  
but on Hawuii G8 , IVoiceCapture-\>GetCaptureState() return 0 and in the same time VoiceCapture\>IsCapturing() is returing true , no errors from states at all, while on other devices works fine. I even tested it on another Hawuii G8 device with the same results , is it a low level bug inside engine related to hardware or what ?

I hope to get any answers from Community.

I was sure 100% from all permissions and .ini settings.

Here is my HeaderFile .

```
// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "CoreMinimal.h"
#include "Components/ActorComponent.h"

#include "Runtime/Online/Voice/Public/VoiceModule.h"
#include "VolumeCapture.generated.h"

UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) )
class MYPROJECT2_API UVolumeCapture : public UActorComponent
{
	GENERATED_BODY()

public:	
	// Sets default values for this component's properties
	UVolumeCapture();

protected:
	// Called when the game starts
	virtual void BeginPlay() override;

public:	
	// Called every frame
	virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override;
	TSharedPtr<IVoiceCapture> VoiceCapture_V;	
	uint32 VoiceCaptureBytesAvailable;
	TArray<uint8> VoiceCaptureBuffer;
	UPROPERTY(EditAnywhere, BlueprintReadWrite)
		float VoiceCaptureVolume;
};

```

And here is my CPP file

```
// Fill out your copyright notice in the Description page of Project Settings.

#include "VolumeCapture.h"
#include "Platform.h"

// Sets default values for this component's properties
UVolumeCapture::UVolumeCapture()
{
	// Set this component to be initialized when the game starts, and to be ticked every frame. You can turn these features
	// off to improve performance if you don't need them.
	PrimaryComponentTick.bCanEverTick = true;

	// ...
}

// Called when the game starts
void UVolumeCapture::BeginPlay()
{
	Super::BeginPlay();
	VoiceCapture_V = FVoiceModule::Get().CreateVoiceCapture();

	bool Success = VoiceCapture_V.IsValid(); //VoiceCapture->Start();
	if (Success)
	{
		VoiceCapture_V->Start();
		UE_LOG(LogTemp, Warning, TEXT("Voice capture started successfully"));
		GEngine->AddOnScreenDebugMessage(-1, 5.0f, FColor::Green, "Voice capture started successfully");
	}
	else
	{
		UE_LOG(LogTemp, Warning, TEXT("Voice capture not started successfully"));
		GEngine->AddOnScreenDebugMessage(-1, 5.0f, FColor::Red, "Voice capture starting failed");
	}
}

// Called every frame
void UVolumeCapture::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
{
	Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
	if (!VoiceCapture_V.IsValid())
	{
		UE_LOG(LogTemp, Warning, TEXT("Voice capture is not valid; skipping the rest of voice capture tick"));
		//GEngine->AddOnScreenDebugMessage(-1, 0.1f, FColor::Red, "Voice Capture is not valid");
		return;
	}
	else
	{
		//GEngine->AddOnScreenDebugMessage(-1, 0.1f, FColor::Green, "valid");
	}
	if (VoiceCapture_V->IsCapturing())
		GEngine->AddOnScreenDebugMessage(-1, 0.05f, FColor::Black, "Capturing data right now");
	else
		GEngine->AddOnScreenDebugMessage(-1, 0.05f, FColor::Black, "Not Capturing");

	
	
	EVoiceCaptureState::Type CaptureState = VoiceCapture_V->GetCaptureState(VoiceCaptureBytesAvailable);	

	UE_LOG(LogTemp, Warning, TEXT("Bytes available: %d\nCapture state: %s"), VoiceCaptureBytesAvailable, EVoiceCaptureState::ToString(CaptureState));

	FString NewString = FString::FromInt(VoiceCaptureBytesAvailable);
	GEngine->AddOnScreenDebugMessage(-1, 0.05f, FColor::Black, NewString);
	VoiceCaptureBuffer.Reset();
	
	if (CaptureState == EVoiceCaptureState::Ok && VoiceCaptureBytesAvailable > 0)
	{
		int16_t VoiceCaptureSample;
		uint32 VoiceCaptureReadBytes;
		float VoiceCaptureTotalSquared = 0;

		VoiceCaptureBuffer.SetNumUninitialized(VoiceCaptureBytesAvailable);

		VoiceCapture_V->GetVoiceData(VoiceCaptureBuffer.GetData(), VoiceCaptureBytesAvailable, VoiceCaptureReadBytes);

		for (int i = 0; i < VoiceCaptureBuffer.Num() / 2; i++)
		{
			VoiceCaptureSample = VoiceCaptureBuffer[i]; //(VoiceCaptureBuffer[i] << 8) | VoiceCaptureBuffer[i];
			VoiceCaptureTotalSquared += ((float)VoiceCaptureSample * (float)VoiceCaptureSample);
		}

		float VoiceCaptureMeanSquare = (2 * (VoiceCaptureTotalSquared / VoiceCaptureBuffer.Num()));
		float VoiceCaptureRms = FMath::Sqrt(VoiceCaptureMeanSquare);
		float VoiceCaptureFinalVolume = ((VoiceCaptureMeanSquare / 32768.0) * 20.f);

		VoiceCaptureVolume = VoiceCaptureFinalVolume;

		GEngine->AddOnScreenDebugMessage(-1, 0.05f, FColor::Blue, FString::Printf(TEXT("VoiceCaptureVolume: %f"), VoiceCaptureVolume));
	}

	if (CaptureState == EVoiceCaptureState::Error)
	{
		GEngine->AddOnScreenDebugMessage(-1, 2.0f, FColor::Emerald, "ERROR");
	}
	if (CaptureState == EVoiceCaptureState::NoData)
	{
		GEngine->AddOnScreenDebugMessage(-1, 0.05f, FColor::Emerald, "NoData");
	}
	if (CaptureState == EVoiceCaptureState::NotCapturing)
	{
		GEngine->AddOnScreenDebugMessage(-1, 1.0f, FColor::Emerald, "NotCapturing");
	}
	if (CaptureState == EVoiceCaptureState::UnInitialized)
	{
		GEngine->AddOnScreenDebugMessage(-1, 1.0f, FColor::Emerald, "UnInitialized");
	}
	if (CaptureState == EVoiceCaptureState::Stopping)
	{
		GEngine->AddOnScreenDebugMessage(-1, 1.0f, FColor::Emerald, "Stopping");
	}
	if (CaptureState == EVoiceCaptureState::BufferTooSmall)
	{
		GEngine->AddOnScreenDebugMessage(-1, 1.0f, FColor::Emerald, "BufferTooSmall");
	}
}	

```

---

<div class="post-metadata">

**Author:** ![Omar\_Vector](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Omar\_Vector](https://forums.unrealengine.com/u/Omar_Vector)\
**Post date:** [June 26, 2018, 8:09pm UTC](https://forums.unrealengine.com/t/ivoicecapture-get-data-return-0-on-android-while-capturing-state-is-ok/428119/2 "2018-06-26T20:09:35Z")

</div>

I really need help in that please

---

<div class="post-metadata">

**Author:** ![Omar\_Vector](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Omar\_Vector](https://forums.unrealengine.com/u/Omar_Vector)\
**Post date:** [June 27, 2018, 1:26pm UTC](https://forums.unrealengine.com/t/ivoicecapture-get-data-return-0-on-android-while-capturing-state-is-ok/428119/3 "2018-06-27T13:26:38Z")

</div>

UP, I need serious help plz

---

<div class="post-metadata">

**Author:** ![Omar\_Vector](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Omar\_Vector](https://forums.unrealengine.com/u/Omar_Vector)\
**Post date:** [July 2, 2018, 3:51am UTC](https://forums.unrealengine.com/t/ivoicecapture-get-data-return-0-on-android-while-capturing-state-is-ok/428119/4 "2018-07-02T03:51:30Z")

</div>

Help plz, how I suppose to solve this

---

<div class="post-metadata">

**Author:** ![Omar\_Vector](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Omar\_Vector](https://forums.unrealengine.com/u/Omar_Vector)\
**Post date:** [July 5, 2018, 3:08am UTC](https://forums.unrealengine.com/t/ivoicecapture-get-data-return-0-on-android-while-capturing-state-is-ok/428119/5 "2018-07-05T03:08:58Z")

</div>

up, I need help plz

---

<div class="post-metadata">

**Author:** ![Omar\_Vector](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Omar\_Vector](https://forums.unrealengine.com/u/Omar_Vector)\
**Post date:** [July 21, 2018, 12:25pm UTC](https://forums.unrealengine.com/t/ivoicecapture-get-data-return-0-on-android-while-capturing-state-is-ok/428119/6 "2018-07-21T12:25:44Z")

</div>

UP ☹ , I need help

---

<div class="post-metadata">

**Author:** ![Omar\_Vector](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Omar\_Vector](https://forums.unrealengine.com/u/Omar_Vector)\
**Post date:** [July 24, 2018, 7:03pm UTC](https://forums.unrealengine.com/t/ivoicecapture-get-data-return-0-on-android-while-capturing-state-is-ok/428119/7 "2018-07-24T19:03:45Z")

</div>

UP ,need help in this

---

<div class="post-metadata">

**Author:** ![WHHwxiaop](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@WHHwxiaop](https://forums.unrealengine.com/u/WHHwxiaop)\
**Post date:** [June 14, 2024, 12:36am UTC](https://forums.unrealengine.com/t/ivoicecapture-get-data-return-0-on-android-while-capturing-state-is-ok/428119/8 "2024-06-14T00:36:47Z")

</div>

hi，after using IVoiceCapture to record multiple times on your computer, the sound capture is incomplete, do you know how to fix it?
