-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New Feature: Use the android TTS feature to speech messages #1813
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
to268
wants to merge
2
commits into
moezbhatti:master
Choose a base branch
from
to268:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,6 +34,7 @@ android { | |
minSdkVersion 21 | ||
targetSdkVersion 29 | ||
} | ||
namespace 'com.moez.QKSMS.domain' | ||
} | ||
|
||
dependencies { | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/* | ||
* Copyright (C) 2017 Moez Bhatti <[email protected]> | ||
* Copyright (C) 2017,2021 Moez Bhatti <[email protected]>,to268 | ||
* | ||
* This file is part of QKSMS. | ||
* | ||
|
@@ -30,7 +30,9 @@ import android.os.Build | |
import android.os.Bundle | ||
import android.provider.ContactsContract | ||
import android.provider.MediaStore | ||
import android.speech.tts.TextToSpeech | ||
import android.text.format.DateFormat | ||
import android.util.Log | ||
import android.view.Menu | ||
import android.view.MenuItem | ||
import androidx.appcompat.app.AlertDialog | ||
|
@@ -66,12 +68,16 @@ import io.reactivex.Observable | |
import io.reactivex.subjects.PublishSubject | ||
import io.reactivex.subjects.Subject | ||
import kotlinx.android.synthetic.main.compose_activity.* | ||
import kotlinx.android.synthetic.main.compose_activity.attachments | ||
import kotlinx.android.synthetic.main.compose_activity.sim | ||
import kotlinx.android.synthetic.main.compose_activity.simIndex | ||
import kotlinx.android.synthetic.main.message_list_item_in.* | ||
import java.text.SimpleDateFormat | ||
import java.util.* | ||
import javax.inject.Inject | ||
import kotlin.collections.HashMap | ||
|
||
class ComposeActivity : QkThemedActivity(), ComposeView { | ||
class ComposeActivity : QkThemedActivity(), ComposeView, TextToSpeech.OnInitListener { | ||
|
||
companion object { | ||
private const val SelectContactRequestCode = 0 | ||
|
@@ -82,12 +88,18 @@ class ComposeActivity : QkThemedActivity(), ComposeView { | |
private const val CameraDestinationKey = "camera_destination" | ||
} | ||
|
||
@Inject lateinit var attachmentAdapter: AttachmentAdapter | ||
@Inject lateinit var chipsAdapter: ChipsAdapter | ||
@Inject lateinit var dateFormatter: DateFormatter | ||
@Inject lateinit var messageAdapter: MessagesAdapter | ||
@Inject lateinit var navigator: Navigator | ||
@Inject lateinit var viewModelFactory: ViewModelProvider.Factory | ||
@Inject | ||
lateinit var attachmentAdapter: AttachmentAdapter | ||
@Inject | ||
lateinit var chipsAdapter: ChipsAdapter | ||
@Inject | ||
lateinit var dateFormatter: DateFormatter | ||
@Inject | ||
lateinit var messageAdapter: MessagesAdapter | ||
@Inject | ||
lateinit var navigator: Navigator | ||
@Inject | ||
lateinit var viewModelFactory: ViewModelProvider.Factory | ||
|
||
override val activityVisibleIntent: Subject<Boolean> = PublishSubject.create() | ||
override val chipsSelectedIntent: Subject<HashMap<String, String?>> = PublishSubject.create() | ||
|
@@ -119,6 +131,7 @@ class ComposeActivity : QkThemedActivity(), ComposeView { | |
private val viewModel by lazy { ViewModelProviders.of(this, viewModelFactory)[ComposeViewModel::class.java] } | ||
|
||
private var cameraDestination: Uri? = null | ||
private var tts: TextToSpeech? = null | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
AndroidInjection.inject(this) | ||
|
@@ -160,6 +173,9 @@ class ComposeActivity : QkThemedActivity(), ComposeView { | |
if (Build.VERSION.SDK_INT <= 22) { | ||
messageBackground.setBackgroundTint(resolveThemeColor(R.attr.bubbleColor)) | ||
} | ||
|
||
// Set tts info | ||
tts = TextToSpeech(this, this) | ||
} | ||
|
||
override fun onStart() { | ||
|
@@ -206,6 +222,7 @@ class ComposeActivity : QkThemedActivity(), ComposeView { | |
toolbar.menu.findItem(R.id.details)?.isVisible = !state.editingMode && state.selectedMessages == 1 | ||
toolbar.menu.findItem(R.id.delete)?.isVisible = !state.editingMode && state.selectedMessages > 0 | ||
toolbar.menu.findItem(R.id.forward)?.isVisible = !state.editingMode && state.selectedMessages == 1 | ||
toolbar.menu.findItem(R.id.speech)?.isVisible = !state.editingMode && state.selectedMessages == 1 | ||
toolbar.menu.findItem(R.id.previous)?.isVisible = state.selectedMessages == 0 && state.query.isNotEmpty() | ||
toolbar.menu.findItem(R.id.next)?.isVisible = state.selectedMessages == 0 && state.query.isNotEmpty() | ||
toolbar.menu.findItem(R.id.clear)?.isVisible = state.selectedMessages == 0 && state.query.isNotEmpty() | ||
|
@@ -251,6 +268,10 @@ class ComposeActivity : QkThemedActivity(), ComposeView { | |
.show() | ||
} | ||
|
||
override fun speechText(text: String) { | ||
tts!!.speak(text, TextToSpeech.QUEUE_FLUSH, null, "") | ||
} | ||
|
||
override fun requestDefaultSms() { | ||
navigator.showDefaultSmsDialog(this) | ||
} | ||
|
@@ -399,4 +420,27 @@ class ComposeActivity : QkThemedActivity(), ComposeView { | |
|
||
override fun onBackPressed() = backPressedIntent.onNext(Unit) | ||
|
||
// Text to speech | ||
override fun onInit(status: Int) { | ||
if (status == TextToSpeech.SUCCESS) { | ||
val result = tts!!.setLanguage(Locale.getDefault()) | ||
|
||
if (result == TextToSpeech.LANG_MISSING_DATA || result == TextToSpeech.LANG_NOT_SUPPORTED) { | ||
Log.e("TTS", "The default language is not supported !") | ||
} | ||
|
||
} else { | ||
Log.e("TTS", "Initialization failed !") | ||
} | ||
} | ||
|
||
override fun onDestroy() { | ||
if (tts != null) { | ||
tts!!.stop() | ||
tts!!.shutdown() | ||
} | ||
|
||
super.onDestroy() | ||
} | ||
|
||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should i add my real name and my email address instead ?