diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 037bbfb..123c88b 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -7,16 +7,20 @@ + + + android:parentActivityName=".MainActivity" /> + + + + + + TTS Server - Help + + + +

What is it?

+

+ TTS Server is an Android-only application that provides a REST-based interface for on-board + TTS engine of your device. The application is aimed on home automation and allows you to give + a second life to your old smartphone, which can now act as a standalone, all-inclusive web TTS + provider for your speech-based home notification system.

+ +

For what?

+

+ Android is provided with a great offline TTS engine for almost every language on the + world. + If you care about high availability of the web TTS provider or you don't want your notifications + go through the Internet to the cloud providers, you can utilise your smartphone to done the job. +

+ +

How does it work?

+

+ TTS Server runs a service with HTTP server that exposes endpoints allowing you + to perform TTS task. As the Android implements its own process-killer, the application needs + to run the service on the foreground (so the notification is always shown) + keeping it alive and preventing it from being killed. Because of that, keep in mind that + the application might drain your battery, so it is recommended to use it only + on the devices being always connected to the power source. +

+ +

Consuming REST interface

+

+ So far, the application provides two endpoints: /say and /wave. + Each endpoint works with JSON-based body, so each request requires a proper + Content-Type header. +

+ +

The /say endpoint

+
+POST /say
+{
+    "text": "The text to be spoken",
+    "language": "en_US"
+}
+
+

Returns: 200 OK with empty body

+

+ The /say endpoint allows you to perform TTS task using device's speakers or the + external ones connected to it via jack, Bluetooth etc. For example if you have some + old PC-speakers you are able to connect your device to them via line port and + get a complete speech-based notification system. +

+ +

The /wave endpoint

+
+POST /wave
+{
+    "text": "The text to be spoken",
+    "language": "en_US"
+}
+
+

Returns: 200 OK with wave file (Content-Type: audio/x-wav)

+

+ The /wave endpoint enables you to download a wav file containing speech of the + provided text. The goal of this endpoint is to provide interface allowing you establishment + of the connection between the TTS Server and some other kind of already running TTS system, + which can invoke the HTTP request to your Android device and do something with returned + wav file. For example, take a look at + my fork of great + Node Sonos HTTP API. + I've already written a TTS plugin in my fork allowing me to connect the TTS Server and my + Sonos speakers right through the Node Sonos HTTP API, which performs the request + to the Android device and puts returned wav file on the Sonos speakers. +

+ + \ No newline at end of file diff --git a/app/src/main/assets/help/stylesheet.css b/app/src/main/assets/help/stylesheet.css new file mode 100644 index 0000000..f6e9922 --- /dev/null +++ b/app/src/main/assets/help/stylesheet.css @@ -0,0 +1,21 @@ +body { + font-family: sans-serif; +} + +code { + background-color: #EFEFEF; + color: #757575; + padding: 0.2rem 0.5rem; + border-radius: 0.2rem; +} + +pre { + background-color: #EFEFEF; + color: #757575; + padding: 1rem; + border-radius: 0.1rem; +} + +a { + color: #8BC34A +} \ No newline at end of file diff --git a/app/src/main/java/io/bartek/MainActivity.kt b/app/src/main/java/io/bartek/MainActivity.kt index 88b3237..98ab65e 100644 --- a/app/src/main/java/io/bartek/MainActivity.kt +++ b/app/src/main/java/io/bartek/MainActivity.kt @@ -1,16 +1,19 @@ package io.bartek -import android.content.* +import android.content.BroadcastReceiver +import android.content.Context +import android.content.Intent +import android.content.IntentFilter import android.os.Build import android.os.Bundle import android.view.Menu import android.view.MenuItem import android.view.View import android.widget.TextView -import android.widget.Toast import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.widget.AppCompatImageButton import androidx.localbroadcastmanager.content.LocalBroadcastManager +import io.bartek.help.HelpActivity import io.bartek.preference.PreferencesActivity import io.bartek.service.ForegroundService import io.bartek.service.ServiceState @@ -38,6 +41,7 @@ class MainActivity : AppCompatActivity() { override fun onOptionsItemSelected(item: MenuItem): Boolean { when(item.itemId) { R.id.open_preferences -> startActivity(Intent(this, PreferencesActivity::class.java)) + R.id.open_help -> startActivity(Intent(this, HelpActivity::class.java)) } return super.onOptionsItemSelected(item) diff --git a/app/src/main/java/io/bartek/help/HelpActivity.kt b/app/src/main/java/io/bartek/help/HelpActivity.kt new file mode 100644 index 0000000..9d84010 --- /dev/null +++ b/app/src/main/java/io/bartek/help/HelpActivity.kt @@ -0,0 +1,30 @@ +package io.bartek.help + +import android.os.Bundle +import android.webkit.WebView +import androidx.appcompat.app.AppCompatActivity +import io.bartek.R +import java.util.* + +class HelpActivity : AppCompatActivity() { + private lateinit var helpView: WebView + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.activity_help) + helpView = findViewById(R.id.help_view) + loadHelp() + } + + private fun loadHelp() { + val lang = Locale.getDefault().language + val file = HELP_FILE.format(".$lang") + .takeIf { resources.assets.list("help")?.contains(it) == true } + ?: HELP_FILE.format("") + helpView.loadUrl("file:///android_asset/help/${file}") + } + + companion object { + private const val HELP_FILE = "help%s.html" + } +} diff --git a/app/src/main/java/io/bartek/preference/PreferencesActivity.kt b/app/src/main/java/io/bartek/preference/PreferencesActivity.kt index aeddc9b..8e252cf 100644 --- a/app/src/main/java/io/bartek/preference/PreferencesActivity.kt +++ b/app/src/main/java/io/bartek/preference/PreferencesActivity.kt @@ -2,7 +2,6 @@ package io.bartek.preference import android.os.Bundle import androidx.appcompat.app.AppCompatActivity -import androidx.preference.PreferenceFragmentCompat import io.bartek.R class PreferencesActivity : AppCompatActivity() { diff --git a/app/src/main/res/drawable/ic_settings.xml b/app/src/main/res/drawable/ic_settings.xml deleted file mode 100644 index 60b3b52..0000000 --- a/app/src/main/res/drawable/ic_settings.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - diff --git a/app/src/main/res/layout/activity_help.xml b/app/src/main/res/layout/activity_help.xml new file mode 100644 index 0000000..2c8deb2 --- /dev/null +++ b/app/src/main/res/layout/activity_help.xml @@ -0,0 +1,12 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/menu/menu_main.xml b/app/src/main/res/menu/menu_main.xml index 89caf7d..dd93f37 100644 --- a/app/src/main/res/menu/menu_main.xml +++ b/app/src/main/res/menu/menu_main.xml @@ -1,5 +1,6 @@ - + + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 82a77e6..de87c84 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -22,4 +22,6 @@ TTS engine settings TTS engine Server + Settings + Help