{"id":18111526,"url":"https://github.com/gotev/android-speech","last_synced_at":"2025-04-04T11:11:47.782Z","repository":{"id":41067079,"uuid":"66761433","full_name":"gotev/android-speech","owner":"gotev","description":"Android speech recognition and text to speech made easy","archived":false,"fork":false,"pushed_at":"2021-06-05T15:49:12.000Z","size":458,"stargazers_count":513,"open_issues_count":1,"forks_count":161,"subscribers_count":21,"default_branch":"master","last_synced_at":"2025-03-28T10:06:59.498Z","etag":null,"topics":["android","recognition","speech","tts"],"latest_commit_sha":null,"homepage":"http://gotev.github.io/android-speech/","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/gotev.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},"funding":{"custom":["https://paypal.me/alexgt"]}},"created_at":"2016-08-28T10:03:38.000Z","updated_at":"2025-03-24T02:20:27.000Z","dependencies_parsed_at":"2022-08-24T05:31:48.153Z","dependency_job_id":null,"html_url":"https://github.com/gotev/android-speech","commit_stats":null,"previous_names":[],"tags_count":17,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gotev%2Fandroid-speech","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gotev%2Fandroid-speech/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gotev%2Fandroid-speech/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gotev%2Fandroid-speech/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gotev","download_url":"https://codeload.github.com/gotev/android-speech/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247166168,"owners_count":20894654,"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","recognition","speech","tts"],"created_at":"2024-11-01T01:06:08.507Z","updated_at":"2025-04-04T11:11:47.766Z","avatar_url":"https://github.com/gotev.png","language":"Java","funding_links":["https://paypal.me/alexgt"],"categories":["人工智能"],"sub_categories":[],"readme":"# Android Speech ![Maven Central](https://img.shields.io/maven-central/v/net.gotev/speech)\n#### [Latest version Release Notes and Demo App](https://github.com/gotev/android-speech/releases/latest) | [Demo App Sources](https://github.com/gotev/android-speech/tree/master/examples/demoapp/app/src/main/java/net/gotev/speechdemo)\nAndroid speech recognition and text to speech made easy.\n\n## Setup\n### Gradle\n```groovy\nimplementation 'net.gotev:speech:x.y.z'\n```\nReplace `x.y.z` with ![Maven Central](https://img.shields.io/maven-central/v/net.gotev/speech)\n\n## Initialization\nTo start using the library, you have to initialize it in your Activity\n```java\npublic class YourActivity extends Activity {\n\n    Override\n    protected void onCreate(Bundle savedInstanceState) {\n        super.onCreate(savedInstanceState);\n        setContentView(R.layout.your_layout);\n\n        Speech.init(this, getPackageName());\n    }\n\n    @Override\n    protected void onDestroy() {\n        // prevent memory leaks when activity is destroyed\n        Speech.getInstance().shutdown();\n    }\n}\n```\n\n## Example\nYou can find a fully working demo app which uses this library in the `examples` directory. Just checkout the project and give it a try.\n\n## Usage\n### Speech recognition\nInside an activity:\n```java\ntry {\n    // you must have android.permission.RECORD_AUDIO granted at this point\n    Speech.getInstance().startListening(new SpeechDelegate() {\n        @Override\n        public void onStartOfSpeech() {\n            Log.i(\"speech\", \"speech recognition is now active\");\n        }\n\n        @Override\n        public void onSpeechRmsChanged(float value) {\n            Log.d(\"speech\", \"rms is now: \" + value);\n        }\n\n        @Override\n        public void onSpeechPartialResults(List\u003cString\u003e results) {\n            StringBuilder str = new StringBuilder();\n            for (String res : results) {\n                str.append(res).append(\" \");\n            }\n\n            Log.i(\"speech\", \"partial result: \" + str.toString().trim());\n        }\n\n        @Override\n        public void onSpeechResult(String result) {\n            Log.i(\"speech\", \"result: \" + result);\n        }\n    });\n} catch (SpeechRecognitionNotAvailable exc) {\n    Log.e(\"speech\", \"Speech recognition is not available on this device!\");\n    // You can prompt the user if he wants to install Google App to have\n    // speech recognition, and then you can simply call:\n    //\n    // SpeechUtil.redirectUserToGoogleAppOnPlayStore(this);\n    //\n    // to redirect the user to the Google App page on Play Store\n} catch (GoogleVoiceTypingDisabledException exc) {\n    Log.e(\"speech\", \"Google voice typing must be enabled!\");\n}\n```\n\n### Release resources\nIn your Activity's `onDestroy`, add:\n```java\n@Override\nprotected void onDestroy() {\n    Speech.getInstance().shutdown();\n}\n```\nTo prevent memory leaks.\n\n### Display progress animation\nAdd this to your layout:\n```xml\n\u003cLinearLayout\n    android:orientation=\"vertical\"\n    android:layout_width=\"wrap_content\"\n    android:layout_height=\"wrap_content\"\n    android:id=\"@+id/linearLayout\"\u003e\n\n    \u003cnet.gotev.speech.ui.SpeechProgressView\n        android:id=\"@+id/progress\"\n        android:layout_width=\"120dp\"\n        android:layout_height=\"150dp\"/\u003e\n\n\u003c/LinearLayout\u003e\n```\nIt's important that the `SpeechProgressView` is always inside a LinearLayout to function properly. You can adjust width and height accordingly to the bar height settings (see below).\n\nthen, when you start speech recognition, pass also the `SpeechProgressView`:\n\n```java\nSpeech.getInstance().startListening(speechProgressView, speechDelegate);\n```\n\n#### Set custom bar colors\nYou can set all the 5 bar colors as you wish. This is just an example:\n```java\nint[] colors = {\n        ContextCompat.getColor(this, android.R.color.black),\n        ContextCompat.getColor(this, android.R.color.darker_gray),\n        ContextCompat.getColor(this, android.R.color.black),\n        ContextCompat.getColor(this, android.R.color.holo_orange_dark),\n        ContextCompat.getColor(this, android.R.color.holo_red_dark)\n};\nspeechProgressView.setColors(colors);\n```\n\n#### Set custom maximum bar height\n```java\nint[] heights = {60, 76, 58, 80, 55};\nspeechProgressView.setBarMaxHeightsInDp(heights);\n```\n\n### Text to speech\nInside an activity:\n```java\nSpeech.getInstance().say(\"say something\");\n```\n\nYou can also provide a callback to receive status:\n```java\nSpeech.getInstance().say(\"say something\", new TextToSpeechCallback() {\n    @Override\n    public void onStart() {\n        Log.i(\"speech\", \"speech started\");\n    }\n\n    @Override\n    public void onCompleted() {\n        Log.i(\"speech\", \"speech completed\");\n    }\n\n    @Override\n    public void onError() {\n        Log.i(\"speech\", \"speech error\");\n    }\n});\n```\n\n## Configuration\nYou can configure various parameters by using the setter methods on the speech instance, which you can get like this anywhere in your code:\n```java\nSpeech.getInstance()\n```\nRefer to JavaDocs for a complete reference.\n\n## Logging\nBy default the library logging is disabled. You can enable debug log by invoking:\n```java\nLogger.setLogLevel(LogLevel.DEBUG);\n```\nwherever you want in your code. You can adjust the level of detail from DEBUG to OFF.\n\nThe library logger uses `android.util.Log` by default, so you will get the output in `LogCat`. If you want to redirect logs to different output or use a different logger, you can provide your own delegate implementation like this:\n```java\nLogger.setLoggerDelegate(new Logger.LoggerDelegate() {\n    @Override\n    public void error(String tag, String message) {\n        //your own implementation here\n    }\n\n    @Override\n    public void error(String tag, String message, Throwable exception) {\n        //your own implementation here\n    }\n\n    @Override\n    public void debug(String tag, String message) {\n        //your own implementation here\n    }\n\n    @Override\n    public void info(String tag, String message) {\n        //your own implementation here\n    }\n});\n```\n\n## Get current locale and voice (since 1.5.0)\nUse `Speech.getInstance().getSpeechToTextLanguage()` and `Speech.getinstance().getTextToSpeechVoice()`. Check the demo app for a complete example.\n\n## Get supported Speech To Text languages and Text To Speech voices (since 1.5.0)\nUse `Speech.getInstance().getSupportedSpeechToTextLanguages(listener)` and `Speech.getInstance().getSupportedTextToSpeechVoices()`. Check the demo app for a complete example.\n\n## Set Speech To Text Language and Text To Speech voice\nUse `Speech.getInstance().setLocale(locale)` and `Speech.getInstance().setVoice(voice)`. Check the demo app for a complete example.\n\n\u003e When you set the locale, the voice is automatically changed to the default voice of that language. If you want to set a particular voice, remember to re-set it every time you change the locale, too.\n\n## Credits\nThanks to @zagum for the original implementation of the [speech recognition view](https://github.com/zagum/SpeechRecognitionView).\n\n## License\n\n    Copyright (C) 2019 Aleksandar Gotev\n\n    Licensed under the Apache License, Version 2.0 (the \"License\");\n    you may not use this file except in compliance with the License.\n    You may obtain a copy of the License at\n\n       http://www.apache.org/licenses/LICENSE-2.0\n\n    Unless required by applicable law or agreed to in writing, software\n    distributed under the License is distributed on an \"AS IS\" BASIS,\n    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n    See the License for the specific language governing permissions and\n    limitations under the License.\n\n## Contributors\nThanks to [Kristiyan Petrov](https://github.com/kristiyanP) for code review, bug fixes and library improvement ideas.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgotev%2Fandroid-speech","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgotev%2Fandroid-speech","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgotev%2Fandroid-speech/lists"}