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
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ import com.google.firebase.vertexai.common.APIController
import com.google.firebase.vertexai.common.AppCheckHeaderProvider
import com.google.firebase.vertexai.type.BidiGenerateContentClientMessage
import com.google.firebase.vertexai.type.Content
import com.google.firebase.vertexai.type.GeminiConnectionHandshakeFailed
import com.google.firebase.vertexai.type.LiveGenerationConfig
import com.google.firebase.vertexai.type.LiveSession
import com.google.firebase.vertexai.type.RequestOptions
import com.google.firebase.vertexai.type.ServiceConnectionHandshakeFailedException
import com.google.firebase.vertexai.type.Tool
import io.ktor.websocket.Frame
import io.ktor.websocket.close
Expand Down Expand Up @@ -103,7 +103,7 @@ internal constructor(
LiveSession(session = webSession, backgroundDispatcher = backgroundDispatcher)
} else {
webSession.close()
throw GeminiConnectionHandshakeFailed()
throw ServiceConnectionHandshakeFailedException()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@

package com.google.firebase.vertexai.type

import android.Manifest
import android.media.AudioFormat
import android.media.AudioManager
import android.media.AudioRecord
import android.media.AudioTrack
import android.media.MediaRecorder
import android.media.audiofx.AcousticEchoCanceler
import androidx.annotation.RequiresPermission
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flow

Expand Down Expand Up @@ -66,7 +68,8 @@ internal class AudioHelper {
}
}

suspend fun startRecording(): Flow<ByteArray> {
@RequiresPermission(Manifest.permission.RECORD_AUDIO)
fun startRecording(): Flow<ByteArray> {

val bufferSize =
AudioRecord.getMinBufferSize(
Expand All @@ -79,7 +82,9 @@ internal class AudioHelper {
bufferSize == AudioRecord.ERROR_BAD_VALUE ||
bufferSize <= 0
) {
throw AudioRecordInitializationFailedException("Audio Record buffer size is invalid")
throw AudioRecordInitializationFailedException(
"Audio Record buffer size is invalid (${bufferSize})"
)
}
audioRecord =
AudioRecord(
Expand All @@ -90,7 +95,9 @@ internal class AudioHelper {
bufferSize
)
if (audioRecord.state != AudioRecord.STATE_INITIALIZED) {
throw AudioRecordInitializationFailedException("Audio Record initialization has failed.")
throw AudioRecordInitializationFailedException(
"Audio Record initialization has failed. State: ${audioRecord.state}"
)
}
if (AcousticEchoCanceler.isAvailable()) {
val echoCanceler = AcousticEchoCanceler.create(audioRecord.audioSessionId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ public class AudioRecordInitializationFailedException(message: String) :
FirebaseVertexAIException(message)

/** Handshake failed with the server */
public class GeminiConnectionHandshakeFailed :
public class ServiceConnectionHandshakeFailedException :
FirebaseVertexAIException("Handshake failed with the server.")

/** Catch all case for exceptions not explicitly expected. */
Expand Down
Loading