Speech Recognition
Convert player voice to text using AI-powered speech recognition
Speech Recognition
The PlayKit SDK provides two complementary components for speech-to-text:
| Component | Use Case |
|---|---|
UPlayKitSTTComponent | Real-time microphone recording + transcription |
UPlayKitSTTClient | Transcribe existing audio files or raw audio data |
Prerequisites
Ensure the AudioCapture plugin is enabled:
- Edit > Plugins
- Search for "Audio Capture"
- Enable it and restart the editor
Real-Time Recording (UPlayKitSTTComponent)
UPlayKitSTTComponent handles the full record-then-transcribe pipeline. Add it to an Actor in the editor (Add Component → PlayKit STT Component).
Blueprint Setup
In the Actor's Event Graph, bind the response event and wire your record/stop logic:
Event BeginPlay
→ Bind Event to OnPlayKitTranscriptionResponded → HandleTranscript
[Key Press E] → Start Recording
[Key Release E] → Stop Recording (transcription starts automatically)
HandleTranscript (Result: FPlayKitTranscriptionResult)
→ Branch (Result.bSuccess)
True → Print String (Result.Text)
False → Print String (Result.ErrorMessage)C++ Setup
#include "Component/PlayKitSTTComponent.h"
UPROPERTY(VisibleAnywhere)
UPlayKitSTTComponent* STTComponent;
void AMyCharacter::BeginPlay()
{
Super::BeginPlay();
STTComponent = FindComponentByClass<UPlayKitSTTComponent>();
STTComponent->OnPlayKitTranscriptionResponded.AddDynamic(
this, &AMyCharacter::HandleTranscript);
STTComponent->OnPlayKitTranscriptionError.AddDynamic(
this, &AMyCharacter::HandleError);
}
void AMyCharacter::StartListening()
{
STTComponent->StartRecording();
}
void AMyCharacter::StopListening()
{
STTComponent->StopRecording();
// Transcription dispatches automatically after StopRecording
}
void AMyCharacter::HandleTranscript(const FPlayKitTranscriptionResult& Result)
{
if (Result.bSuccess)
ProcessVoiceCommand(Result.Text);
else
UE_LOG(LogTemp, Warning, TEXT("Transcription failed: %s"), *Result.ErrorMessage);
}Transcription Options
For explicit control, use StartTranscription instead of relying on auto-dispatch:
FPlayKitTranscriptionRequest Request;
Request.Language = TEXT("en"); // Optional language hint
STTComponent->StartTranscription(Request);Or StartTranscriptionSimple() to transcribe the last recording with default settings.
File/Data Transcription (UPlayKitSTTClient)
Use UPlayKitSTTClient when you already have an audio file or raw PCM data. Add it as an ActorComponent.
#include "Client/PlayKitSTTClient.h"
UPROPERTY(VisibleAnywhere)
UPlayKitSTTClient* STTClient;
void AMyActor::BeginPlay()
{
Super::BeginPlay();
STTClient = FindComponentByClass<UPlayKitSTTClient>();
STTClient->OnTranscriptionComplete.AddDynamic(
this, &AMyActor::HandleTranscription);
}
void AMyActor::TranscribeFile(const FString& FilePath)
{
STTClient->TranscribeFile(FilePath);
}
void AMyActor::TranscribeRawAudio(const TArray<uint8>& AudioBytes)
{
STTClient->TranscribeAudioData(AudioBytes, TEXT("recording.wav"));
}
void AMyActor::HandleTranscription(const FPlayKitTranscriptionResult& Result)
{
if (Result.bSuccess)
UE_LOG(LogTemp, Log, TEXT("Transcript: %s"), *Result.Text);
}Language Support
// Set a default language on the component
STTClient->SetLanguage(TEXT("en"));
// Or transcribe a file with an explicit language
STTClient->TranscribeFileWithLanguage(FilePath, TEXT("zh"));Supported codes: "en", "zh", "ja", "ko", "es", and all other Whisper-supported languages. Leave empty for auto-detect.
Voice Commands Example
void AGameController::ProcessVoiceCommand(const FString& Transcript)
{
FString LowerText = Transcript.ToLower();
if (LowerText.Contains(TEXT("open inventory")))
OpenInventory();
else if (LowerText.Contains(TEXT("attack")))
PerformAttack();
else
{
// Pass to NPC via Talk()
NPCClient->Talk(Transcript);
}
}Platform Considerations
Windows / macOS / Linux
Full support for microphone recording.
Consoles
Check platform-specific microphone permission requirements.
Mobile
Request microphone permission before recording and handle denial gracefully.
Blueprint Nodes Reference
| Node | Component | Description |
|---|---|---|
Start Recording | UPlayKitSTTComponent | Begin microphone capture |
Stop Recording | UPlayKitSTTComponent | Stop capture (transcription auto-starts) |
Start Transcription | UPlayKitSTTComponent | Transcribe with explicit options |
Start Transcription Simple | UPlayKitSTTComponent | Transcribe with defaults |
Transcribe File | UPlayKitSTTClient | Transcribe a local audio file |
Transcribe Audio Data | UPlayKitSTTClient | Transcribe raw PCM bytes |
Set Language | UPlayKitSTTClient | Set the recognition language |
Next Steps
- Combine with NPC Conversations for voice-driven dialogue
- Explore Text Generation for AI responses
- See API Reference for complete documentation