Skip to content
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

Release version 2.0 #5

Merged
merged 34 commits into from
Jun 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
11e3bfd
Delegate the TTS onInit() callback to the starting SpeakerActivity
drmfinlay May 30, 2020
ec82413
Improve and simplify TTS initialisation and language handling
drmfinlay Jun 1, 2020
6e83188
Add menu item for reinitialising the TTS engine
drmfinlay Jun 1, 2020
236a523
Add icon for the TTS settings menu item
drmfinlay Jun 1, 2020
41c6f9c
Cancel any TTS notifications present at the end of freeSpeaker()
drmfinlay Jun 1, 2020
9c949b5
Change SpeakerEventListeners to use ApplicationEx as the Context
drmfinlay Jun 1, 2020
8a66351
Fix error messages that sometimes appear when stopping synthesis
drmfinlay Jun 1, 2020
009c88e
Change SynthesisEventListener to require a Context object again
drmfinlay Jun 1, 2020
8eeedba
Fix some Speaker class documentation comments
drmfinlay Jun 1, 2020
02c3835
Improve TTS synthesis error messages
drmfinlay Jun 1, 2020
20bf917
Handle lines longer than Android's maximum speech input length
drmfinlay Jun 2, 2020
8a5f33d
Try to cancel notifications and release audio focus on TTS errors
drmfinlay Jun 2, 2020
7c319db
Fallback on the current system locale for unavailable languages
drmfinlay Jun 2, 2020
7ebd26d
Improve TTS initialisation/ready messages
drmfinlay Jun 4, 2020
982845d
Replace two uses of TextToSpeech.stop() with Speaker.stopSpeech()
drmfinlay Jun 9, 2020
3598fe9
Change output wave file names to use '.wav' file extensions instead
drmfinlay Jun 10, 2020
c73f86e
Add WaveUtil.kt file with code to read and join wave files together
drmfinlay Jun 11, 2020
39d100a
Clean up part of the Speaker.speak(lines) method
drmfinlay Jun 11, 2020
1fddcd6
Change synthesise text file functionality to handle long files
drmfinlay Jun 11, 2020
be53d6c
Use mutable set for SynthesisEventListener.utteranceIds value
drmfinlay Jun 12, 2020
7d2b980
Handle the special case of joining 1 sound file in joinWaveFiles()
drmfinlay Jun 12, 2020
d4fd571
Add error handling for joinWaveFiles()
drmfinlay Jun 12, 2020
153c9a9
Update Gradle and other dependencies
drmfinlay Jun 12, 2020
00cf6f8
Change TTS notifications to display progress based on utterance IDs
drmfinlay Jun 12, 2020
54edf03
Change ReadFilesFragment to read all lines at once
drmfinlay Jun 12, 2020
9b8034f
Make the SpeakerActivity base class abstract instead of "open"
drmfinlay Jun 14, 2020
200ff5d
Add settings screen for changing the app's TTS settings
drmfinlay Jun 15, 2020
9ea016e
Fix issue where the system speech rate and/or pitch is overwritten
drmfinlay Jun 16, 2020
f831448
Add "Use default" buttons to all TTS preference dialogs
drmfinlay Jun 16, 2020
b38324f
Bump minimum Android SDK version to 21 (Lollipop)
drmfinlay Jun 17, 2020
409f4f7
Remove conditional branches for SDK version 20 after version bump
drmfinlay Jun 17, 2020
9e2b803
Add workarounds for some internal errors raised by the TTS API
drmfinlay Jun 17, 2020
0e079fd
Reinitialise TTS after selecting the default engine in the settings
drmfinlay Jun 17, 2020
5b721b3
Release version 2.0
drmfinlay Jun 17, 2020
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
9 changes: 5 additions & 4 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ android {

defaultConfig {
applicationId "com.danefinlay.ttsutil"
minSdkVersion 20
minSdkVersion 21
targetSdkVersion 28
versionCode 1
versionName "1.0"
versionCode 2
versionName "2.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}

Expand Down Expand Up @@ -38,9 +38,10 @@ dependencies {
androidTestImplementation('com.android.support.test.espresso:espresso-core:3.0.2')
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:preference-v7:28.0.0'
implementation 'org.jetbrains.anko:anko-sdk15:0.9'
implementation 'org.jetbrains.anko:anko-support-v4:0.9.1'
implementation 'com.android.support.constraint:constraint-layout:2.0.0-beta3'
implementation 'com.android.support.constraint:constraint-layout:2.0.0-beta6'
implementation 'com.android.support:design:28.0.0'
testImplementation 'junit:junit:4.13-beta-3'
}
Expand Down
62 changes: 60 additions & 2 deletions app/src/main/java/com/danefinlay/ttsutil/ApplicationEx.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,47 @@
package com.danefinlay.ttsutil

import android.app.Application
import android.content.res.Resources
import android.media.AudioAttributes
import android.media.AudioFocusRequest
import android.media.AudioManager
import android.media.AudioManager.OnAudioFocusChangeListener
import android.os.Build
import android.speech.tts.TextToSpeech
import android.support.v7.preference.PreferenceManager
import org.jetbrains.anko.audioManager
import org.jetbrains.anko.longToast
import org.jetbrains.anko.notificationManager
import java.util.*

class ApplicationEx : Application() {

var speaker: Speaker? = null
private set

var errorMessageId: Int? = null

/**
* Return the system's current locale.
*
* This will be a Locale object representing the user's preferred language as
* set in the system settings.
*/
val currentSystemLocale: Locale
get() {
val systemConfig = Resources.getSystem().configuration
val systemLocale = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
systemConfig?.locales?.get(0)
} else {
@Suppress("deprecation")
systemConfig?.locale
}

// Return the system locale. Fallback on the default JVM locale if
// necessary.
return systemLocale ?: Locale.getDefault()
}

private val audioFocusGain = AudioManager.AUDIOFOCUS_GAIN_TRANSIENT
private val audioFocusRequest: AudioFocusRequest by lazy {
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.O) {
Expand Down Expand Up @@ -89,15 +118,44 @@ class ApplicationEx : Application() {
}
}

fun startSpeaker() {
fun startSpeaker(initListener: TextToSpeech.OnInitListener,
preferredEngine: String?) {
if (speaker == null) {
speaker = Speaker(this, true)
// Try to get the preferred engine package from shared preferences if
// it is null.
val engineName = preferredEngine ?:
PreferenceManager.getDefaultSharedPreferences(this)
.getString("pref_tts_engine", null)

// Initialise the Speaker object.
speaker = Speaker(this, true, initListener,
engineName)
}
}

/**
* Show the speaker error message (if set) or the default speaker not ready
* message.
*/
fun showSpeakerNotReadyMessage() {
val defaultMessageId = R.string.speaker_not_ready_message
val errorMessageId = errorMessageId
longToast(errorMessageId ?: defaultMessageId)
}

fun freeSpeaker() {
speaker?.free()
speaker = null

// Cancel any TTS notifications present.
notificationManager.cancel(SPEAKING_NOTIFICATION_ID)
notificationManager.cancel(SYNTHESIS_NOTIFICATION_ID)
}

fun reinitialiseSpeaker(initListener: TextToSpeech.OnInitListener,
preferredEngine: String?) {
freeSpeaker()
startSpeaker(initListener, preferredEngine)
}

override fun onLowMemory() {
Expand Down
7 changes: 3 additions & 4 deletions app/src/main/java/com/danefinlay/ttsutil/Notifications.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

package com.danefinlay.ttsutil

import android.app.Notification
import android.app.NotificationChannel
import android.app.NotificationManager
import android.app.PendingIntent
Expand Down Expand Up @@ -93,9 +92,10 @@ private fun getNotificationBuilder(ctx: Context, notificationId: Int):
}


fun buildSpeakerNotification(ctx: Context, notificationId: Int): Notification {
fun speakerNotificationBuilder(ctx: Context, notificationId: Int):
NotificationCompat.Builder {
val builder = getNotificationBuilder(ctx, notificationId)
builder.apply {
return builder.apply {
// Set the title and text depending on the notification ID.
when (notificationId) {
SPEAKING_NOTIFICATION_ID -> {
Expand All @@ -111,5 +111,4 @@ fun buildSpeakerNotification(ctx: Context, notificationId: Int): Notification {
}
}
}
return builder.build()
}
Loading