Skip to content

Audio Prompt For Alert Events

Audio prompt for alert events

This tutorial shows how to handle audio prompts for alert events and violation warnings.

Get started

Some alert events can be prompted via audio guidance if a drive session is created with both alert and audio guidance component enabled. All supported alert events have a switch to control whether it should be prompted or not, some of them share the same switch.

The following table shows the mapping between alert event and audio prompt types.

alert event type audio prompt type
tn::drive::models::v1::AlertType::SpeedCamera tn::drive::models::v1::AudioPromptType::SpeedCamera
tn::drive::models::v1::AlertType::RedlightCamera tn::drive::models::v1::AudioPromptType::RedLightCamera
tn::drive::models::v1::AlertType::BuslaneCamera tn::drive::models::v1::AudioPromptType::BusLaneCamera
tn::drive::models::v1::AlertType::RedlightAndSpeedCamera tn::drive::models::v1::AudioPromptType::RedLightAndSpeedCamera
tn::drive::models::v1::AlertType::SectionStartCamera tn::drive::models::v1::AudioPromptType::SectionStartCamera
tn::drive::models::v1::AlertType::SectionEndCamera tn::drive::models::v1::AudioPromptType::SectionEndCamera
tn::drive::models::v1::AlertType::Tollbooth tn::drive::models::v1::AudioPromptType::Tollbooth
tn::drive::models::v1::AlertType::SchoolZone tn::drive::models::v1::AudioPromptType::SchoolZone
tn::drive::models::v1::AlertType::RailwayCrossing tn::drive::models::v1::AudioPromptType::CrossingRailway
tn::drive::models::v1::AlertType::Accident tn::drive::models::v1::AudioPromptType::AccidentAhead
tn::drive::models::v1::AlertType::AccidentCleared tn::drive::models::v1::AudioPromptType::AccidentCleared
tn::drive::models::v1::AlertType::EntryBlock tn::drive::models::v1::AudioPromptType::EntryBlocked
tn::drive::models::v1::AlertType::EntryReopen tn::drive::models::v1::AudioPromptType::EntryReopened
tn::drive::models::v1::AlertType::ExitBlock tn::drive::models::v1::AudioPromptType::ExitBlocked
tn::drive::models::v1::AlertType::ExitReopen tn::drive::models::v1::AudioPromptType::ExitReopened
tn::drive::models::v1::AlertType::HazardousRoad tn::drive::models::v1::AudioPromptType::HazardousRoadAhead
tn::drive::models::v1::AlertType::HazardousRoadPassed tn::drive::models::v1::AudioPromptType::HazardousRoadPassed
tn::drive::models::v1::AlertType::LaneRestriction tn::drive::models::v1::AudioPromptType::LaneRestrictionsAhead
tn::drive::models::v1::AlertType::LaneRestrictionOver tn::drive::models::v1::AudioPromptType::LaneRestrictionsOver
tn::drive::models::v1::AlertType::PoliceCheckPoint tn::drive::models::v1::AudioPromptType::PoliceCheckPointAhead
tn::drive::models::v1::AlertType::BlockedRoad tn::drive::models::v1::AudioPromptType::RoadBlockAhead
tn::drive::models::v1::AlertType::RoadConstruction tn::drive::models::v1::AudioPromptType::RoadworksAhead
tn::drive::models::v1::AlertType::RoadConstructionEnded tn::drive::models::v1::AudioPromptType::RoadworksEnded
tn::drive::models::v1::AlertType::Congestion tn::drive::models::v1::AudioPromptType::CongestionAhead
tn::drive::models::v1::AlertType::TrafficFlow tn::drive::models::v1::AudioPromptType::CongestionAhead
tn::drive::models::v1::AlertType::CongestionCleared tn::drive::models::v1::AudioPromptType::CongestionCleared
tn::drive::models::v1::AlertType::SpeedCamera tn::drive::models::v1::AudioPromptType::MobileSpeedCamera
tn::drive::models::v1::AlertType::TimeSpeedLimit tn::drive::models::v1::AudioPromptType::TimeSpeedLimit
tn::drive::models::v1::AlertType::CongestionHazard tn::drive::models::v1::AudioPromptType::CongestionHazard
tn::drive::models::v1::AlertType::AccidentHazard tn::drive::models::v1::AudioPromptType::AccidentHazard
tn::drive::models::v1::AlertType::BlackSpot tn::drive::models::v1::AudioPromptType::AccidentHazard
tn::drive::models::v1::AlertType::CrossBorder tn::drive::models::v1::AudioPromptType::TownEntryPointAhead

Notice: tn::drive::models::v1::AlertType::SpeedCamera is mapped to two tn::drive::models::v1::AudioPromptType, one is SpeedCamera and the other is MobileSpeedCamera. It depends on the fixture status of the camera. For FixtureStatus::None and FixtureStatus::Permanent, it will be prompted as a SpeedCamera, while for FixtureStatus::Preannounced and FixtureStatus::Mobile, it will be prompted as a MobileSpeedCamera.

Notice: tn::drive::models::v1::AlertType::Congestion and tn::drive::models::v1::AlertType::TrafficFlow share the same audio prompt type switch tn::drive::models::v1::AudioPromptType::CongestionAhead.

Notice: tn::drive::models::v1::AlertType::AccidentHazard and tn::drive::models::v1::AlertType::BlackSpot share the same audio prompt type switch tn::drive::models::v1::AudioPromptType::AccidentHazard.

The following table shows the mapping between violation warnings and audio prompt types. | violation warning type | audio prompt type | |-|-| | tn::drive::models::v1::OverSpeedWarning | tn::drive::models::v1::AudioPromptType::OverSpeed |

Handle audio prompt for alert event

Make a customized audio listener to handle alert event and violation warning prompts. Refer to tutorial for audio instructions for how to play audio instructions.

class AudioInstructionObserver : public tn::drive::api::AudioEventListener
{
public:
    void onAudioInstruction(const tn::drive::models::v1::AudioInstruction& instruction) override
    {
        // same alert event and violation warning will be prompted only once by drive session
        if (instruction.type == tn::drive::models::v1::AudioInstruction::AudioType::Alert)
        {
            // you should check if there's any audio guidance prompt being played before playing a new one
            // to avoid conflict with existing one
            playAudioInstruction(instruction);
        }
        // omit other types ...
    }
};

Customize audio prompt for alert event

Audio prompt for all supported alert events and violation warnings are enabled by default. It can be tuned for each alert event and violation warning.

For example, the default audio prompt content for cross-border alert events is something like "town entry point ahead". It may not be appropriate for all cross-border alerts, e.g., when crossing a country border, "town" is not a proper word. In this case, you can turn off the default audio prompt for cross-border alert and request the CountryBorderPrep prompt when approaching it.

1
2
3
4
5
6
// turn off cross border alert
const std::map<tn::drive::models::v1::AudioPromptType, bool> switches = {
    { tn::drive::models::v1::AudioPromptType::TownEntryPointAhead, false }
};

driveSession->enableAudioPrompt(switches);

Listening to cross border alert events to handle country border crossing cases. Refer to tutorial for handling cross border alerts for details.