Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
accompanistPermissions = "0.34.0"
agp = "8.7.3"
constraintlayoutCompose = "1.1.0"
pipecatClient = "0.3.7"
pipecatClient = "1.1.0"
kotlin = "2.0.20"
coreKtx = "1.15.0"
lifecycleRuntimeKtx = "2.8.7"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ android {
}

compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}

kotlinOptions {
jvmTarget = "1.8"
jvmTarget = "11"
}

buildFeatures {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
package ai.pipecat.small_webrtc_client

import ai.pipecat.client.RTVIClient
import ai.pipecat.client.RTVIClientOptions
import ai.pipecat.client.RTVIClientParams
import ai.pipecat.client.RTVIEventCallbacks
import ai.pipecat.client.PipecatClient
import ai.pipecat.client.PipecatClientOptions
import ai.pipecat.client.PipecatEventCallbacks
import ai.pipecat.client.result.Future
import ai.pipecat.client.result.RTVIError
import ai.pipecat.client.result.Result
import ai.pipecat.client.small_webrtc_transport.PipecatClientSmallWebRTC
import ai.pipecat.client.small_webrtc_transport.SmallWebRTCTransport
import ai.pipecat.client.types.ActionDescription
import ai.pipecat.client.types.APIRequest
import ai.pipecat.client.types.BotReadyData
import ai.pipecat.client.types.Participant
import ai.pipecat.client.types.PipecatMetrics
import ai.pipecat.client.types.ServiceConfig
import ai.pipecat.client.types.Tracks
import ai.pipecat.client.types.Transcript
import ai.pipecat.client.types.TransportState
import ai.pipecat.client.types.Value
import ai.pipecat.small_webrtc_client.utils.Timestamp
import android.content.Context
import android.util.Log
Expand All @@ -34,14 +34,12 @@ class VoiceClientManager(private val context: Context) {
private const val TAG = "VoiceClientManager"
}

private val client = mutableStateOf<RTVIClient?>(null)
private val client = mutableStateOf<PipecatClientSmallWebRTC?>(null)

val state = mutableStateOf<TransportState?>(null)

val errors = mutableStateListOf<Error>()

val actionDescriptions =
mutableStateOf<Result<List<ActionDescription>, RTVIError>?>(null)

val expiryTime = mutableStateOf<Timestamp?>(null)

Expand All @@ -66,15 +64,9 @@ class VoiceClientManager(private val context: Context) {
return
}

val options = RTVIClientOptions(
params = RTVIClientParams(baseUrl = null),
enableMic = true,
enableCam = true
)

state.value = TransportState.Disconnected

val callbacks = object : RTVIEventCallbacks() {
val callbacks = object : PipecatEventCallbacks() {
override fun onTransportStateChanged(state: TransportState) {
[email protected] = state
}
Expand All @@ -86,18 +78,12 @@ class VoiceClientManager(private val context: Context) {
}
}

override fun onBotReady(version: String, config: List<ServiceConfig>) {

Log.i(TAG, "Bot ready. Version $version, config: $config")

override fun onBotReady(data: BotReadyData) {
Log.i(TAG, "Bot ready: $data")
botReady.value = true

client.value?.describeActions()?.withCallback {
actionDescriptions.value = it
}
}

override fun onPipecatMetrics(data: PipecatMetrics) {
override fun onMetrics(data: PipecatMetrics) {
Log.i(TAG, "Pipecat metrics: $data")
}

Expand Down Expand Up @@ -138,17 +124,11 @@ class VoiceClientManager(private val context: Context) {
[email protected] = mic
}

override fun onConnected() {
expiryTime.value = client.value?.expiry?.let(Timestamp::ofEpochSecs)
}

override fun onDisconnected() {
expiryTime.value = null
actionDescriptions.value = null
botIsTalking.value = false
userIsTalking.value = false
state.value = null
actionDescriptions.value = null
botReady.value = false
tracks.value = null

Expand All @@ -165,9 +145,21 @@ class VoiceClientManager(private val context: Context) {
}
}

val client = RTVIClient(SmallWebRTCTransport.Factory(context, baseUrl), callbacks, options)
val options = PipecatClientOptions(
enableMic = true,
enableCam = true,
callbacks = callbacks
)

val client = PipecatClient(
transport = SmallWebRTCTransport(context),
options = options
)

client.connect().displayErrors().withErrorCallback {
client.startBotAndConnect(APIRequest(
endpoint = baseUrl,
requestData = Value.Object(),
)).displayErrors().withErrorCallback {
callbacks.onDisconnected()
}

Expand Down
Loading