项目作者: hiteshsahu

项目描述 :
One line solution for Android Text to speech(TTS) & Speech to Text(STT) translation problem
高级语言: Kotlin
项目地址: git://github.com/hiteshsahu/Android-TTS-STT.git
创建时间: 2016-07-13T02:18:21Z
项目社区:https://github.com/hiteshsahu/Android-TTS-STT

开源协议:

下载


Android Easy Text to Speech & Speech to Text without annoying dialog(TTS & STT)

Android TTS and STT is one line solution to convert text to speech(TTS) & speech to text(STT) in your Android App.

  • Convert Speech to text without annoying dialog.
  • Convert Text to Speech with error handling and callbacks
  • Written in Kotlin and compiled for upto Android 28.
  • TranslatorFactory class uses Factory pattern to create translators instances and use callbacks return success and error.

Usage

  1. //SPEECH TO TEXT DEMO
  2. speechToText.setOnClickListener({ view ->
  3. Snackbar.make(view, "Speak now, App is listening", Snackbar.LENGTH_LONG)
  4. .setAction("Action", null).show()
  5. TranslatorFactory
  6. .instance
  7. .with(TranslatorFactory.TRANSLATORS.SPEECH_TO_TEXT,
  8. object : ConversionCallback {
  9. override fun onSuccess(result: String) {
  10. sttOutput.text = result
  11. }
  12. override fun onCompletion() {
  13. }
  14. override fun onErrorOccurred(errorMessage: String) {
  15. erroConsole.text = "Speech2Text Error: $errorMessage"
  16. }
  17. }).initialize("Speak Now !!", this@HomeActivity)
  18. })
  19. //TEXT TO SPEECH DEMO
  20. textToSpeech.setOnClickListener({ view ->
  21. val stringToSpeak :String = ttsInput.text.toString()
  22. if (null!=stringToSpeak && stringToSpeak.isNotEmpty()) {
  23. TranslatorFactory
  24. .instance
  25. .with(TranslatorFactory.TRANSLATORS.TEXT_TO_SPEECH,
  26. object : ConversionCallback {
  27. override fun onSuccess(result: String) {
  28. }
  29. override fun onCompletion() {
  30. }
  31. override fun onErrorOccurred(errorMessage: String) {
  32. erroConsole.text = "Text2Speech Error: $errorMessage"
  33. }
  34. })
  35. .initialize(stringToSpeak, this)
  36. } else {
  37. ttsInput.setText("Invalid input")
  38. Snackbar.make(view, "Please enter some text to speak", Snackbar.LENGTH_LONG).show()
  39. }
  40. })

Screenshots of Demo screen

Use in your project

Simply drop translation_engine package in your project and start using wherever you like. Dont forget to add RECORD_AUDIO permission in Maninfest. For Marshmallow and above you will need to request permission (refer abstract class BasePermissionActivity in the demo).

  1. <uses-permission android:name="android.permission.RECORD_AUDIO" ></uses-permission>

Reference: https://stackoverflow.com/questions/6316937/how-can-i-use-speech-recognition-without-the-annoying-dialog-in-android-phones

Licence

  1. Copyright 2019 Hitesh Kumar Sahu
  2. Licensed under the Apache License, Version 2.0 (the "License");
  3. you may not use this file except in compliance with the License.
  4. You may obtain a copy of the License at
  5. http://www.apache.org/licenses/LICENSE-2.0
  6. Unless required by applicable law or agreed to in writing, software
  7. distributed under the License is distributed on an "AS IS" BASIS,
  8. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  9. See the License for the specific language governing permissions and
  10. limitations under the License.