{"id":20398935,"url":"https://github.com/aiyu-ayaan/tts-engine","last_synced_at":"2025-04-12T13:22:03.975Z","repository":{"id":150441468,"uuid":"597465974","full_name":"aiyu-ayaan/tts-engine","owner":"aiyu-ayaan","description":"The TTS-Engine is a simple and efficient library that provides Text-to-Speech functionality for Android applications. The library uses state-of-the-art speech synthesis technology to generate high-quality speech from text, and supports multiple languages and voices.","archived":false,"fork":false,"pushed_at":"2024-06-25T09:38:49.000Z","size":122,"stargazers_count":22,"open_issues_count":0,"forks_count":3,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-26T08:05:31.895Z","etag":null,"topics":["android","jetpack-compose","kotlin","kotlin-android","text-speech-app","text-to-speech","texttospeech-android","texttospeech-api","tts","tts-android"],"latest_commit_sha":null,"homepage":"","language":"Kotlin","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/aiyu-ayaan.png","metadata":{"files":{"readme":"README.MD","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":["aiyu-ayaan"],"buy_me_a_coffee":"aiyuayaan"}},"created_at":"2023-02-04T16:34:48.000Z","updated_at":"2025-02-19T09:11:22.000Z","dependencies_parsed_at":"2024-11-15T05:30:23.171Z","dependency_job_id":null,"html_url":"https://github.com/aiyu-ayaan/tts-engine","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aiyu-ayaan%2Ftts-engine","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aiyu-ayaan%2Ftts-engine/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aiyu-ayaan%2Ftts-engine/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aiyu-ayaan%2Ftts-engine/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/aiyu-ayaan","download_url":"https://codeload.github.com/aiyu-ayaan/tts-engine/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248571903,"owners_count":21126539,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["android","jetpack-compose","kotlin","kotlin-android","text-speech-app","text-to-speech","texttospeech-android","texttospeech-api","tts","tts-android"],"created_at":"2024-11-15T04:25:19.135Z","updated_at":"2025-04-12T13:22:03.948Z","avatar_url":"https://github.com/aiyu-ayaan.png","language":"Kotlin","funding_links":["https://github.com/sponsors/aiyu-ayaan","https://buymeacoffee.com/aiyuayaan"],"categories":[],"sub_categories":[],"readme":"# TTS Engine\n\nA simple and efficient library that provides Text-to-Speech functionality for Android applications.\n\n\u003ca href=\"https://firebasestorage.googleapis.com/v0/b/aiyu-ayaan.appspot.com/o/demo.mp4?alt=media\u0026token=3919f7d8-7a8e-406d-a5ea-5a3a00d914db\" traget=\"_blank\"\u003e\n\t\u003cimage src=\"https://firebasestorage.googleapis.com/v0/b/aiyu-ayaan.appspot.com/o/TTS-Engine.png?alt=media\u0026token=2fb4886c-c9ed-4d73-8288-e9d13619f1d0\"\n       height=\"400\" width=\"400\"\u003e\u003c/image\u003e\n\u003c/a\u003e\n\n## Features\n\n- Support for multiple languages and voices\n- Easy-to-use API\n\n## Installation\n\nAdd the library to your project using Gradle:\n\n```groovy\nallprojects {\n\t\trepositories {\n\t\t\tmaven { url 'https://jitpack.io' }\n\t\t}\n\t}\n```\n\n```groovy\ndependencies {\n\t        implementation 'com.github.aiyu-ayaan:tts-engine:Tag'\n\t}\n```\n\n## Usage\n\nUsing the library is straightforward and simple. Here is an example of how to use it in your code:\n\n```kotlin\n    TextToSpeechHelper\n        .getInstance(activity)\n        .registerLifecycle(owner)\n        .speak(message)\n        .highlight()\n        .onHighlight { pair -\u003e\n            Log.d(TAG, \"speak: ${pair.first} - ${pair.second}\")\n        }\n        .onDone {\n            Log.d(TAG, \"speak: done\")\n        }\n        .onError {\n            Log.d(TAG, \"speak: $it\")\n        }\n```\n\n- `activity` is the activity that will be used to initialize the TTS engine.\n\n- `owner` is the lifecycle owner that will be used to register the TTS engine lifecycle observer and can handle the lifecycle events.\n\n- `message` is the text that will be spoken.\n\n- `highlight()` is an optional method that will highlight the spoken words in the text.\n\n- `onHighlight()` is an optional method that will be called when a word is spoken.\n\n- `onDone()` is an method that will be called when the text is spoken.\n\n- `onError()` is an method that will be called when an error occurs.\n\n## Code Example\n\n### For Jetpack Compose, check out the example below:\n\n`MainActivity.kt`\n\n```kotlin\nclass MainActivity : ComponentActivity() {\n    override fun onCreate(savedInstanceState: Bundle?) {\n        super.onCreate(savedInstanceState)\n        setContent {\n            TTSLibraryTheme {\n                val viewModel = MainViewModel()\n                val resource = stringResource(id = R.string.des)\n                val text = remember { resource }\n\n//                screen\n                Surface(\n                    modifier = Modifier.fillMaxSize(),\n                    color = MaterialTheme.colorScheme.background\n                ) {\n                    Screen(\n                        state = text,\n                        viewModel = viewModel,\n                    ) {\n                        speak(\n                            this,\n                            this as LifecycleOwner,\n                            text,\n                            viewModel\n                        )\n                    }\n                }\n\n            }\n        }\n    }\n}\n\n@Composable\nfun Screen(\n    modifier: Modifier = Modifier,\n    viewModel: MainViewModel,\n    state: String,\n    onButtonClick: () -\u003e Unit = {},\n) {\n    Column(\n        modifier = modifier\n            .fillMaxSize()\n            .padding(16.dp),\n        verticalArrangement = Arrangement.Center,\n        horizontalAlignment = Alignment.CenterHorizontally\n    ) {\n        val s = viewModel.getState().value\n        TTSText(\n            textAlign = TextAlign.Center,\n            textHighlightBuilder = TextHighlightBuilder(\n                text = state,\n                s\n            ),\n        )\n        Spacer(modifier = Modifier.padding(16.dp))\n        Button(onClick = onButtonClick) {\n            Text(text = stringResource(id = R.string.speak))\n        }\n    }\n}\n\n\nprivate fun speak(\n    activity: Activity,\n    owner: LifecycleOwner,\n    message: String,\n    viewModel: MainViewModel\n) {\n    TextToSpeechHelper\n        .getInstance(activity)\n        .registerLifecycle(owner)\n        .speak(message)\n        .highlight()\n        .onHighlight { pair -\u003e\n            viewModel.updateState(pair)\n        }\n        .onDone {\n            Log.d(TAG, \"speak: done\")\n        }\n        .onError {\n            Log.d(TAG, \"speak: $it\")\n        }\n}\n\n```\n\n`MainViewModel.kt`\n\n```kotlin\nclass MainViewModel : ViewModel() {\n    private val state = mutableStateOf(Pair(0, 0))\n\n    fun updateState(pair: Pair\u003cInt, Int\u003e) {\n        state.value = pair\n    }\n\n    fun getState(): State\u003cPair\u003cInt, Int\u003e\u003e = state\n}\n```\n\n### For XML layouts, check out the example below:\n\n```kotlin\nclass MainActivity : AppCompatActivity() {\n    override fun onCreate(savedInstanceState: Bundle?) {\n        super.onCreate(savedInstanceState)\n        setContentView(R.layout.activity_main)\n        val textView = findViewById\u003cTextView\u003e(R.id.text_view)\n        val button = findViewById\u003cButton\u003e(R.id.button)\n        val message = getString(R.string.des)\n        button.setOnClickListener {\n            speak(\n                this,\n                this as LifecycleOwner,\n                message,\n                textView\n            )\n        }\n    }\n\n    private fun speak(\n        activity: Activity,\n        owner: LifecycleOwner,\n        message: String,\n        textView: TextView\n    ) {\n        TextToSpeechHelper\n            .getInstance(activity)\n            .registerLifecycle(owner)\n            .speak(message)\n            .highlight()\n            .onHighlight { pair -\u003e\n                textView.highlightText(pair.first, pair.second)\n            }\n            .onDone {\n                Log.d(TAG, \"speak: done\")\n            }\n            .onError {\n                Log.d(TAG, \"speak: $it\")\n            }\n    }\n}\n```\n\n- `TextView.highlightText()` is an extension method that highlights the spoken words in the text.\n\n## Methods in TextToSpeechHelper class\n\n- `Method 1: registerLifecycle(owner: LifecycleOwner)`\n  Registers the lifecycle of the given owner.\n\n- `Method 2: initTTS()`\n  Initializes the Text-to-Speech engine.\n\n- `Method 3: speak(message: String)`\n  Generates speech from the given message.\n\n- `Method 4: highlight()`\n  Highlights the text in the TextView.\n\n- `Method 5: removeHighlight()`\n  Removes the highlight from the text in the TextView.\n\n- `Method 6: destroy(action: (() -\u003e Unit))`\n  Destroys the Text-to-Speech engine and removes all listeners.\n\n- `Method 7: onStart(onStartListener: () -\u003e Unit)`\n  Sets the onStart listener.\n\n- `Method 8: onDone(onCompleteListener: () -\u003e Unit)`\n  Sets the onDone listener.\n\n- `Method 9: onError(onErrorListener: (String) -\u003e Unit)`\n  Sets the onError listener.\n\n- `Method 10: onHighlight(onHighlightListener: (Pair\u003cInt, Int\u003e) -\u003e Unit)`\n  Sets the onHighlight listener.\n\n- `Method 11: setCustomActionForDestroy(action: () -\u003e Unit)`\n  Sets the custom action to be performed when the Text-to-Speech engine is destroyed.\n\n- `Method 12: setLanguage(locale: Locale)`\n  Sets the language for the Text-to-Speech engine.\n\n- `Method 13: setPitchAndSpeed(pitch: Float, speed: Float)`\n  Sets the pitch and speed of the speech generated by the Text-to-Speech engine.\n\n- `Method 14: resetPitchAndSpeed()`\n  Resets the pitch and speed of the speech generated by the Text-to-Speech engine to the default values.\n\n## Contributing\n\nIf you would like to contribute to the library, please fork the repository and create a pull request.\n\n## License\n\n```\nMIT License\n\nCopyright (c) 2023 Ayaan\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n`\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faiyu-ayaan%2Ftts-engine","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faiyu-ayaan%2Ftts-engine","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faiyu-ayaan%2Ftts-engine/lists"}