Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,299 changes: 1,048 additions & 251 deletions README.md

Large diffs are not rendered by default.

13 changes: 13 additions & 0 deletions android/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,2 +1,15 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_MICROPHONE" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_MEDIA_PLAYBACK" />

<application>
<service
android:name=".DeepgramAudioService"
android:enabled="true"
android:exported="false"
android:foregroundServiceType="microphone|mediaPlayback" />
</application>

</manifest>
85 changes: 85 additions & 0 deletions android/src/main/java/com/deepgram/DeepgramAudioService.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package com.deepgram

import android.app.Notification
import android.app.NotificationChannel
import android.app.NotificationManager
import android.app.Service
import android.content.Context
import android.content.Intent
import android.os.Build
import android.os.IBinder

class DeepgramAudioService : Service() {
companion object {
private const val CHANNEL_ID = "deepgram_audio_channel"
private const val CHANNEL_NAME = "Deepgram Audio"
private const val NOTIFICATION_ID = 43123

fun start(context: Context) {
val intent = Intent(context, DeepgramAudioService::class.java)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
context.startForegroundService(intent)
} else {
context.startService(intent)
}
}

fun stop(context: Context) {
val intent = Intent(context, DeepgramAudioService::class.java)
context.stopService(intent)
}
}

override fun onBind(intent: Intent?): IBinder? = null

override fun onCreate() {
super.onCreate()
createNotificationChannelIfNeeded()
}

override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
val notification = buildNotification()
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
startForeground(
NOTIFICATION_ID,
notification,
android.content.pm.ServiceInfo.FOREGROUND_SERVICE_TYPE_MICROPHONE or
android.content.pm.ServiceInfo.FOREGROUND_SERVICE_TYPE_MEDIA_PLAYBACK
)
} else {
startForeground(NOTIFICATION_ID, notification)
}

return START_STICKY
}

private fun createNotificationChannelIfNeeded() {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) return

val manager = getSystemService(Context.NOTIFICATION_SERVICE) as? NotificationManager
?: return

val channel = NotificationChannel(
CHANNEL_ID,
CHANNEL_NAME,
NotificationManager.IMPORTANCE_LOW
)
channel.description = "Keeps Deepgram audio capture and playback active"
manager.createNotificationChannel(channel)
}

private fun buildNotification(): Notification {
val builder = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
Notification.Builder(this, CHANNEL_ID)
} else {
Notification.Builder(this)
}

return builder
.setContentTitle("Deepgram Audio Active")
.setContentText("Recording or playback is running")
.setSmallIcon(android.R.drawable.stat_sys_speakerphone)
.setOngoing(true)
.build()
}
}
Loading
Loading