Audio Playback, Speech & Haptics
This content is for v1.2.0. Switch to the latest version for up-to-date documentation.
ZKite 1.2.0 provides native audio output, Android Text-to-Speech (TTS), and granular haptic feedback through zkite.audio and zkite.haptics.
Audio Playback
Section titled “Audio Playback”Play bundled local sound files, app assets, or downloaded FileRef objects:
from zkite import audio
# Start playback (returns a MediaPlayer handle)player = await audio.play("assets/chime.wav", volume=0.8)
# Control playbackawait player.pause()await player.seek(2.5) # Seek to 2.5 secondsawait player.resume()
# Check player state (returns "playing", "paused", "stopped", etc.)current_state = await player.state()
# Stop and release native resourcesawait player.stop()Audio Focus & Hardware Routing
Section titled “Audio Focus & Hardware Routing”- Hardware Routing: Automatically routes audio to whichever output device Android is actively using (built-in speaker, wired earphones, or connected Bluetooth A2DP audio devices).
- Audio Focus Loss: If another app requests audio focus (such as an incoming phone call or GPS direction prompt), playback pauses automatically.
- Background Behavior: Audio players pause when your application leaves the foreground. Resuming after returning to the app is explicit.
- Concurrency Limit: Up to 8 concurrent active players can exist simultaneously. Always call
await player.stop()when playback is no longer needed.
Text-to-Speech (TTS)
Section titled “Text-to-Speech (TTS)”Speak text using Android’s installed system speech synthesis engine:
from zkite import audio
# Speak text using default system languageawait audio.speak("File uploaded successfully!")
# Specify an explicit language tag (e.g. en-US, es-ES, hi-IN, fr-FR)await audio.speak("Bonjour, bienvenue dans ZKite", language="fr-FR")- Synthesis Engine: Uses the user’s configured default TTS engine (such as Google Speech Services or Samsung TTS).
- Language Support: Requires that the requested language voice pack is installed on the user’s device. If the language data is missing, ZKite falls back gracefully to the device default locale.
Haptics & Vibration
Section titled “Haptics & Vibration”Haptics bridge the tactile gap between software and hardware. ZKite offers both semantic UI feedback and timed vibration patterns.
1. Semantic Haptic Feedback (haptics.perform)
Section titled “1. Semantic Haptic Feedback (haptics.perform)”Semantic haptics produce Android-standard micro-vibrations tailored for UI controls:
from zkite import haptics
# Trigger semantic effects on user interactionshaptics.perform("click") # Standard button or tab taphaptics.perform("confirm") # Successful action or completionhaptics.perform("reject") # Error, validation failure, or cancelled draghaptics.perform("long_press") # Contextual menu or card holdhaptics.perform("keyboard") # Soft virtual keyboard keypress- Zero Permissions Needed: Semantic feedback uses Android’s View haptic subsystem and does not require the
VIBRATEpermission. - Honors User Preferences: If the user has disabled haptic feedback in their Android System Settings,
perform()quietly respects their choice.
2. Timed Vibration Patterns (haptics.vibrate)
Section titled “2. Timed Vibration Patterns (haptics.vibrate)”For alerts, alarms, or game feedback, use explicit vibrations:
from zkite import haptics
# Single vibration pulse in millisecondsawait haptics.vibrate(duration_ms=120)
# Custom pattern: [delay_ms, vibrate_ms, delay_ms, vibrate_ms, ...]await haptics.vibrate(pattern=[0, 80, 50, 80])
# Stop vibration immediatelyawait haptics.stop()- Permission: Triggering custom vibration patterns automatically causes the scanner to infer the
VIBRATEmanifest permission. - Safety Limits: Patterns are bounded to a maximum duration of 10 seconds to avoid runaway battery drain; infinite repeating vibration loops are prohibited.
