Inspiration

Second Sense — Alert Manager (Pair B)

Overview

Second Sense is an Android assistive-device project. This module provides spoken alerts through Android’s TextToSpeech engine and tactile warnings through Android vibration APIs.

It also includes a test screen for trying alert phrases, adjusting vibration strength, and viewing diagnostic feedback.

Features

  • Spoken alerts: Reads custom messages aloud, with presets such as Obstacle, Turn Left, and Battery Low.
  • Vibration alerts: Sends tactile warnings with adjustable strength from 1 to 255.
  • Test controls: Includes Speak and Vibrate buttons, strength presets, and a diagnostic console.

How It Works

Speech alerts

The speak(text: String) function waits for Android’s TextToSpeech engine to initialize. It then speaks the alert and clears queued speech before playing the latest message.

fun speak(text: String) {
    if (!isTtsReady) {
        pendingSpeechText = text
        return
    }

    tts?.speak(
        text,
        TextToSpeech.QUEUE_FLUSH,
        null,
        "Alert_${System.currentTimeMillis()}"
    )
}

Vibration alerts

The vibrate(strength: Int) function limits the requested strength to the supported range. On Android 8.0 and later, it uses VibrationEffect; it also handles devices without amplitude control and older Android versions.

fun vibrate(strength: Int, durationMillis: Long = 400L) {
    val amplitude = strength.coerceIn(1, 255)

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        val effect = if (vibrator.hasAmplitudeControl()) {
            VibrationEffect.createOneShot(durationMillis, amplitude)
        } else {
            VibrationEffect.createOneShot(
                durationMillis,
                VibrationEffect.DEFAULT_AMPLITUDE
            )
        }
        vibrator.vibrate(effect)
    } else {
        vibrator.vibrate(durationMillis)
    }
}

Project Structure

second-sense/
├── app/
│   ├── src/
│   │   ├── main/
│   │   │   ├── AndroidManifest.xml
│   │   │   ├── java/com/secondsense/alertmanager/
│   │   │   │   ├── AlertManager.kt
│   │   │   │   └── MainActivity.kt
│   │   │   └── res/
│   │   │       ├── layout/activity_main.xml
│   │   │       ├── values/
│   │   │       └── drawable/
│   │   └── test/
│   │       └── java/com/secondsense/alertmanager/
│   │           └── AlertManagerTest.kt
│   └── build.gradle.kts
├── gradle/wrapper/
├── build.gradle.kts
└── settings.gradle.kts

Run and Test

  1. Open the second-sense project in Android Studio and let Gradle sync.
  2. Connect an Android phone or start an emulator, then run the app.
  3. Tap Speak to hear a text alert.
  4. Adjust the strength slider or choose a preset, then tap Vibrate to try the haptic alert. ## What it does

How we built it

Challenges we ran into

Accomplishments that we're proud of

What we learned

What's next for second sense

Built With

Share this project:

Updates

Submission history