Can somebody share event states for Flutter?
# support
a
I'm want to know the event state when the speech starts and ends. I've seen documentation for web where it is explicitly mentioned with states such as "speeh-start" and "speech-end". In flutter, i couldn't find any mention of such states in the documentation. I've searched quite a bit around this for flutter but to no avail. I've attached the screenshot where it is mentioned that other states are in "message" but there is no further clarity on types. https://cdn.discordapp.com/attachments/1352512475970670592/1352512476259946510/Screenshot_2025-03-21_at_10.50.52_AM.png?ex=67de48e6&is=67dcf766&hm=5f87a71b56fcada1aa4d330f61d328ff2a39fc7f280f7b88849bcc5a6b789e66&
s
@alrightokay In the Flutter SDK, speech events are handled differently compared to the Web SDK. While the Web SDK has explicit event types like
speech-start
and
speech-end
, in the Flutter SDK, these events are delivered through a more generalized event system, specifically within the
message
event type. ### How Events Work in Flutter SDK According to the documentation found on GitHub for the Flutter SDK, events are handled like this:
Copy code
dart
vapi.onEvent.listen((event) {
    if (event.label == "call-start") {
        print('call started');
    }
    if (event.label == "call-end") {
        print('call ended');
    }

    // Speech statuses, function calls and transcripts will be sent via messages
    if (event.label == "message") {
        print(event.value);
    }
});
The key note here is that "Speech statuses, function calls and transcripts will be sent via messages". This means that unlike the Web SDK, which has dedicated event types, the Flutter SDK delivers speech updates within the
message
event. ### Speech Update Message Structure From the codebase search results, I found that speech updates have a specific structure. When you receive a message event, you need to check if it's a speech update by examining its type:
Copy code
dart
if (event.label == "message") {
    var message = event.value;
    if (message['type'] == 'speech-update') {
        // This is a speech update message
        String status = message['status']; // Will be either 'started' or 'stopped'
        String role = message['role'];     // Will be either 'assistant' or 'user'
        
        // Handle the speech update accordingly
        if (status == 'started' && role == 'assistant') {
            // Assistant started speaking
        } else if (status == 'stopped' && role == 'user') {
            // User stopped speaking
        }
    }
}
### Speech Update States From the code search, I found that speech updates have these fields: 1. `type`: Will be 'speech-update' 2. `status`: Can be either 'started' or 'stopped' 3. `role`: Can be either 'assistant' or 'user' This means you can detect four states: - Assistant speech started (
status: 'started', role: 'assistant'
) - Assistant speech stopped (
status: 'stopped', role: 'assistant'
) - User speech started (
status: 'started', role: 'user'
) - User speech stopped (
status: 'stopped', role: 'user'
) ### Android SDK Example For reference, I also found how this is implemented in the Android SDK, which may give you a clearer picture of how to handle these events:
Copy code
kotlin
lifecycleScope.launch {
    vapi.eventFlow.collect { event ->
        when (event) {
            is Vapi.Event.SpeechUpdate -> println("Speech update: ${event.status}, ${event.role}")
            // Other event types...
        }
    }
}
In the Android SDK, speech updates are handled as a specific event type rather than through the generic message event. However, the underlying data structure (with
status
and
role
fields) appears to be the same. ## Conclusion To detect speech start and end events in your Flutter application using the VAPI SDK, you need to: 1. Listen for events with
vapi.onEvent.listen
2. Filter for events where
event.label == "message"
3. Check if the message has
type: 'speech-update'
4. Check the
status
('started' or 'stopped') and
role
('assistant' or 'user') to determine the specific speech state