From 3a41689f3ea0f7d4bf70b453a9d44e810223b684 Mon Sep 17 00:00:00 2001 From: Bnyro Date: Sat, 21 Sep 2024 16:31:53 +0200 Subject: [PATCH] fix: tts doesn't work (closes #442) --- .idea/other.xml | 263 ------------------ .../translate/ui/components/TTSButton.kt | 48 ---- .../ui/components/TranslationField.kt | 16 +- 3 files changed, 15 insertions(+), 312 deletions(-) delete mode 100644 .idea/other.xml delete mode 100644 app/src/main/java/com/bnyro/translate/ui/components/TTSButton.kt diff --git a/.idea/other.xml b/.idea/other.xml deleted file mode 100644 index 0d3a1fbb1..000000000 --- a/.idea/other.xml +++ /dev/null @@ -1,263 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/app/src/main/java/com/bnyro/translate/ui/components/TTSButton.kt b/app/src/main/java/com/bnyro/translate/ui/components/TTSButton.kt deleted file mode 100644 index d4ddb58ad..000000000 --- a/app/src/main/java/com/bnyro/translate/ui/components/TTSButton.kt +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright (c) 2024 You Apps - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package com.bnyro.translate.ui.components - -import androidx.compose.material.icons.Icons -import androidx.compose.material.icons.filled.VolumeUp -import androidx.compose.runtime.Composable -import androidx.compose.ui.platform.LocalContext -import com.bnyro.translate.ui.models.TranslationModel -import com.bnyro.translate.util.SpeechHelper - -@Composable -fun TTSButton( - viewModel: TranslationModel, - languageCode: String, - text: String -) { - val context = LocalContext.current - - if (viewModel.engine.supportsAudio) { - StyledIconButton( - imageVector = Icons.Default.VolumeUp - ) { - viewModel.playAudio(languageCode, text) - } - } else if (SpeechHelper.ttsAvailable) { - StyledIconButton( - imageVector = Icons.Default.VolumeUp - ) { - SpeechHelper.speak(context, text, languageCode) - } - } -} diff --git a/app/src/main/java/com/bnyro/translate/ui/components/TranslationField.kt b/app/src/main/java/com/bnyro/translate/ui/components/TranslationField.kt index 314fc9086..3f2ceea6f 100644 --- a/app/src/main/java/com/bnyro/translate/ui/components/TranslationField.kt +++ b/app/src/main/java/com/bnyro/translate/ui/components/TranslationField.kt @@ -30,6 +30,7 @@ import androidx.compose.material.icons.Icons import androidx.compose.material.icons.filled.ContentCopy import androidx.compose.material.icons.filled.DoneAll import androidx.compose.material.icons.filled.Share +import androidx.compose.material.icons.filled.VolumeUp import androidx.compose.material3.MaterialTheme import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue @@ -46,6 +47,7 @@ import com.bnyro.translate.R import com.bnyro.translate.db.obj.Language import com.bnyro.translate.ui.models.TranslationModel import com.bnyro.translate.util.Preferences +import com.bnyro.translate.util.SpeechHelper @Composable fun TranslationField( @@ -122,7 +124,19 @@ fun TranslationField( } ) - TTSButton(translationModel, text, language.code) + if (translationModel.engine.supportsAudio) { + StyledIconButton( + imageVector = Icons.Default.VolumeUp + ) { + translationModel.playAudio(language.code, text) + } + } else if (SpeechHelper.ttsAvailable) { + StyledIconButton( + imageVector = Icons.Default.VolumeUp + ) { + SpeechHelper.speak(context, text, language.code) + } + } } }