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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,5 @@ google-services.json

# Android Profiling
*.hprof

.DS_Store
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@ package ai.elimu.common.utils.data.repository

import ai.elimu.common.utils.data.model.tts.QueueMode
import android.speech.tts.UtteranceProgressListener
import java.util.Locale

interface TextToSpeechRepository {
suspend fun speak(text: CharSequence, queueMode: QueueMode, utteranceId: String)
fun isSpeaking(): Boolean
fun stop()
fun setOnUtteranceProgressListener(listener: UtteranceProgressListener): Int
fun playSilentUtterance(durationInMs: Long, queueMode: Int, utteranceId: String?): Int
fun setSpeechRate(speechRate: Float): Int
fun setLanguage(loc: Locale?): Int
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package ai.elimu.common.utils.data.repository
import ai.elimu.common.utils.data.model.tts.QueueMode
import ai.elimu.common.utils.data.repository.local.LocalTextToSpeechDataSource
import android.speech.tts.UtteranceProgressListener
import java.util.Locale
import javax.inject.Inject

class TextToSpeechRepositoryImpl @Inject constructor(
Expand Down Expand Up @@ -32,4 +33,12 @@ class TextToSpeechRepositoryImpl @Inject constructor(
): Int {
return localDataSource.playSilentUtterance(durationInMs, queueMode, utteranceId)
}

override fun setSpeechRate(speechRate: Float): Int {
return localDataSource.setSpeechRate(speechRate)
}

override fun setLanguage(loc: Locale?): Int {
return localDataSource.setLanguage(loc)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package ai.elimu.common.utils.data.repository.local

import ai.elimu.common.utils.data.model.tts.QueueMode
import android.speech.tts.UtteranceProgressListener
import java.util.Locale

interface LocalTextToSpeechDataSource {
suspend fun speak(text: CharSequence, queueMode: QueueMode, utteranceId: String)
Expand All @@ -12,4 +13,6 @@ interface LocalTextToSpeechDataSource {
durationInMs: Long, queueMode: Int,
utteranceId: String?
): Int
fun setSpeechRate(speechRate: Float): Int
fun setLanguage(loc: Locale?): Int
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import android.os.Bundle
import android.speech.tts.TextToSpeech
import android.speech.tts.UtteranceProgressListener
import android.util.Log
import java.util.Locale
import javax.inject.Inject

class LocalTextToSpeechDataSourceImpl @Inject constructor(
Expand Down Expand Up @@ -34,4 +35,12 @@ class LocalTextToSpeechDataSourceImpl @Inject constructor(
override fun playSilentUtterance(durationInMs: Long, queueMode: Int, utteranceId: String?): Int {
return tts.playSilentUtterance(durationInMs, queueMode, utteranceId)
}

override fun setSpeechRate(speechRate: Float): Int {
return tts.setSpeechRate(speechRate)
}

override fun setLanguage(loc: Locale?): Int {
return tts.setLanguage(loc)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package ai.elimu.common.utils.viewmodel

import ai.elimu.common.utils.data.model.tts.QueueMode
import android.speech.tts.UtteranceProgressListener
import java.util.Locale

interface TextToSpeechViewModel {
fun speak(text: CharSequence, queueMode: QueueMode, utteranceId: String)
Expand All @@ -12,4 +13,6 @@ interface TextToSpeechViewModel {
durationInMs: Long, queueMode: Int,
utteranceId: String?
): Int
fun setSpeechRate(speechRate: Float): Int
fun setLanguage(loc: Locale?): Int
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import androidx.lifecycle.ViewModel
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.launch
import java.util.Locale
import javax.inject.Inject

@HiltViewModel
Expand Down Expand Up @@ -94,4 +95,12 @@ class TextToSpeechViewModelImpl @Inject constructor(
): Int {
return textToSpeechRepository.playSilentUtterance(durationInMs, queueMode, utteranceId)
}

override fun setSpeechRate(speechRate: Float): Int {
return textToSpeechRepository.setSpeechRate(speechRate)
}

override fun setLanguage(loc: Locale?): Int {
return textToSpeechRepository.setLanguage(loc)
}
}