//sorisdk/com.iplateia.sorisdk/SORIAudioRecognizer
SORIAudioRecognizer
open class SORIAudioRecognizer(applicationId: String, secretKey: String)
The primary entry point for the SORI SDK that handles audio recognition with network resilience.
This class provides the main interface for initializing and controlling the SORI SDK. It manages authentication, audio pack updates, listener callbacks, and the recognition service with comprehensive network handling capabilities.
Key Features
- Audio Recognition: On-device audio fingerprinting and matching
- Network Resilience: Automatic request queuing and retry on network failures
- Configurable Behavior: Customize network handling through SORIConfig
- Lifecycle Management: Automatic service binding and unbinding
- Campaign Retrieval: Fetches associated campaigns for recognized audio
Network Handling
The SDK includes built-in network resilience:
- Failed requests due to network unavailability are automatically queued
- Queued requests are retried when network connectivity is restored
- Requests older than the configured timeout are automatically discarded
- All behavior is configurable through
Example Usage
kotlin
// Create listener for SDK events
val listener = object : ISORIListener {
override fun onCampaignFound(campaign: SORICampaign) {
println("Campaign found: ${campaign.name}")
}
override fun onNetworkError(materialId: String, error: String) {
println("Network error for $materialId: $error")
}
override fun onRequestQueued(materialId: String, queueCount: Int) {
println("Request queued. Total pending: $queueCount")
}
}
// Initialize recognizer with credentials
val sori = SORIAudioRecognizer("your_application_id", "your_secret_key")
// Configure network handling (optional)
val config = SORIConfig(
enableDelayedSending = true,
maxPendingTimeMillis = 600000L, // 10 minutes
autoRetryOnNetworkRecovery = true
)
sori.setConfig(config)
// Set listener and start recognition
sori.setListener(context, listener)
sori.startRecognition(context)
Since
1.0.0
See also
ISORIListener | for handling SDK events |
SORIConfig | for configuration options |
SORICampaign | for campaign data structure |
Constructors
SORIAudioRecognizer | [androidJvm] constructor(applicationId: String, secretKey: String) Creates a new SORIAudioRecognizer instance with the specified credentials |
Types
Name | Summary |
---|---|
Companion | [androidJvm] object Companion |
HandleUrlException | [androidJvm] open class HandleUrlException(message: String) : Exception |
NotificationProvider | [androidJvm] interface NotificationProvider Interface for delegate an audio recognition service foreground notification. You can implement this interface to customize the notification. |
Properties
Name | Summary |
---|---|
locationProvider | [androidJvm] var locationProvider: ILocationProvider? |
metadataProvider | [androidJvm] var metadataProvider: IMetadataProvider? |
Functions
Name | Summary |
---|---|
clearState | [androidJvm] fun clearState(ctx: Context) Clears the match state of the SORI Audio Recognition Service. This method is useful to reset the state of the service. example usage: |
getRemainingServiceTime | [androidJvm] fun getRemainingServiceTime(): Long Gets the remaining service runtime in milliseconds before the Android 15 time limit. Returns -1 if there's no time limit (pre-Android 15), if the service is not running, or if the service is not bound. |
getServiceIntent | [androidJvm] fun getServiceIntent(ctx: Context, title: String? = "SORI Audio Recognizer", body: String? = "Listening...", icon: Int? = android.R.drawable.ic_menu_info_details): Intent Creates an intent to start the SORI Audio Recognition Service. This intent can be used to start the service from an activity or another component. example usage: |
handleActionURL | [androidJvm] fun handleActionURL(ctx: Context, campaign: SORICampaign) fun handleActionURL(ctx: Context, url: URL) fun handleActionURL(ctx: Context, url: String) Visits the actual action URL that retrieves from the API Server. |
isServiceApproachingTimeLimit | [androidJvm] fun isServiceApproachingTimeLimit(): Boolean Checks if the service is approaching the Android 15 time limit. Returns true if less than 5 minutes remain before the time limit. Returns false if the service is not running, not bound, or on pre-Android 15 devices. |
setConfig | [androidJvm] fun setConfig(config: SORIConfig) Configure network handling behavior for the SORI SDK. This allows customization of how the SDK handles network unavailability. |
setListener | [androidJvm] fun setListener(ctx: Context, listener: ISORIListener) Set the listener interface for SORI SDK events. It helps to subscribe to the useful events like campaign found, service state changes, etc. |
setLocationProvider | [androidJvm] fun setLocationProvider(provider: ILocationProvider) Set the location provider for the SORI SDK. |
setMetadataProvider | [androidJvm] fun setMetadataProvider(provider: IMetadataProvider) Set the metadata provider for the SORI SDK. |
startRecognition | [androidJvm] fun startRecognition(ctx: Context, title: String? = null, body: String? = null, icon: Int? = null) Starts the SORI Audio Recognition Service. example usage: |
stopRecognition | [androidJvm] fun stopRecognition(ctx: Context) Stops the SORI Audio Recognition Service. example usage: |
updateDatabase | [androidJvm] suspend fun updateDatabase(ctx: Context): UpdateResult Updates the audio recognition database by checking for and downloading new audiopacks. This method can be called independently of the startRecognition method. |