{"id":13741575,"url":"https://github.com/cmusphinx/TLSphinx","last_synced_at":"2025-05-08T21:34:44.883Z","repository":{"id":34107882,"uuid":"37936243","full_name":"cmusphinx/TLSphinx","owner":"cmusphinx","description":"Swift wrapper around Pocketsphinx","archived":false,"fork":true,"pushed_at":"2019-01-04T23:42:05.000Z","size":29040,"stargazers_count":15,"open_issues_count":0,"forks_count":11,"subscribers_count":7,"default_branch":"master","last_synced_at":"2024-11-15T11:36:28.016Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"tryolabs/TLSphinx","license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cmusphinx.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-06-23T18:13:09.000Z","updated_at":"2022-02-03T08:11:03.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/cmusphinx/TLSphinx","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cmusphinx%2FTLSphinx","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cmusphinx%2FTLSphinx/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cmusphinx%2FTLSphinx/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cmusphinx%2FTLSphinx/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cmusphinx","download_url":"https://codeload.github.com/cmusphinx/TLSphinx/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253153171,"owners_count":21862319,"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":[],"created_at":"2024-08-03T04:01:00.459Z","updated_at":"2025-05-08T21:34:41.940Z","avatar_url":"https://github.com/cmusphinx.png","language":"C","readme":"# TLSphinx\n\nTLSphinx is a Swift wrapper around [Pocketsphinx], a portable library based on [CMU Sphinx], that allow an application to perform speech recognition **without the audio ever leaving the device**\n\nThis repository has two main parts. The first is a syntetized version of the [pocketsphinx](http://sourceforge.net/projects/cmusphinx/files/pocketsphinx/5prealpha/) and [sphinx base] repositories with a module map to access the library as a [Clang module]. This module is accessed under the name `Shpinx` and has two submodules: `Pocket` and `Base` in reference to _pocketsphinx_ and _sphinx base_.\n\nThe second part is `TLSphinx`, a Swift framework that uses the `Sphinx` Clang module and exposes a Swift-like API that talks to _pocketsphinx_.\n\n_Note: I write a blog post about `TLSphinx` [here](http://blog.tryolabs.com/2015/06/15/tlsphinx-automatic-speech-recognition-asr-in-swift/) at the [Tryolabs Blog]. Check it out for a short history about why I wrote this._\n\n## Usage\n\nThe framework provides three classes:\n- `Config` describe the configuration needed to recognize speech.\n- `Decoder` is the main class that provides the API to perform all decoding.\n- `Hypotesis` is the result of a decode attempt. It has a `text` and a `score` properties.\n\n#### Config\n\nRepresents the _cmd_ln_t_ opaque structure in `Sphinx`. The default constructor takes an array of tuples with the form `(param name, param value)` where _\"param name\"_ is the name of one of the parameters recognized by `Sphinx`. In this example we are passing the acustic model, the language model and the dictionary. For a complete list of recognized parameters check the [Sphinx docs].\n\nThe class has a public property to turn on/off the debug info from `Sphinx`:\n```swift\npublic var showDebugInfo: Bool\n```\n\n#### Decoder\n\nRepresent the _ps_decoder_t_ opaque struct in `Sphinx`. The default constructor take a `Config` object as parameter.\n\nThis has the functions to perform the decode from a file or from the mic. The result is returned in an optional `Hypotesis` object, following the naming convention of the _Pocketsphinx_ API. The functions are:\n\nTo decode speech from a file:\n```swift\npublic func decodeSpeechAtPath (filePath: String, complete: (Hypotesis?) -\u003e ())\n```\nThe audio pointed by `filePath` must have the following characteristics:\n- single-channel (monaural)\n- little-endian\n- unheadered\n- 16-bit signed\n- PCM\n- sampled at 16000 Hz\n\nTo control the size of the buffer used to read the file, the `Decoder` class has a public property\n```swift\npublic var bufferSize: Int\n```\n\nTo decode a live audio stream from the mic:\n```swift\npublic func startDecodingSpeech (utteranceComplete: (Hypotesis?) -\u003e ())\npublic func stopDecodingSpeech ()\n```\n\nYou can use the same `Decoder` instance many times.\n\n#### Hypotesis\n\nThis struct represents the result of a _decode_ attempt. It has a `text` property with the best scored text and a `score` with the score value. This struct implements `Printable` so you can print it with `println(hypotesis_value)`.\n\n### Examples\n\n#### Processing an Audio File\n\nAs an example let's see how to decode the speech in an audio file. To do so you first need to create a `Config` object and pass it to the `Decoder` constructor. With the decoder you can perform automatic speech recognition from an audio file like so:\n\n```swift\nimport TLSphinx\n\nlet hmm = ...   // Path to the acustic model\nlet lm = ...    // Path to the languaje model\nlet dict = ...  // Path to the languaje dictionary\n\nif let config = Config(args: (\"-hmm\", hmm), (\"-lm\", lm), (\"-dict\", dict)) {\n  if let decoder = Decoder(config:config) {\n      \n      let audioFile = ... // Path to an audio file\n      \n      decoder.decodeSpeechAtPath(audioFile) {\n          \n          if let hyp: Hypotesis = $0 {\n              // Print the decoder text and score\n              println(\"Text: \\(hyp.text) - Score: \\(hyp.score)\")\n          } else {\n              // Can't decode any speech because of an error\n          }\n      }\n  } else {\n      // Handle Decoder() fail\n  }\n} else {\n  // Handle Config() fail  \n}\n```\nThe decode is performed with the `decodeSpeechAtPath` function in the bacground. Once the process finishes,  the `complete` closure is called in the main thread.\n\n#### Speech from the Mic\n\n```swift\nimport TLSphinx\n\nlet hmm = ...   // Path to the acoustic model\nlet lm = ...    // Path to the language model\nlet dict = ...  // Path to the language dictionary\n\nif let config = Config(args: (\"-hmm\", hmm), (\"-lm\", lm), (\"-dict\", dict)) {\n  if let decoder = Decoder(config:config) {\n      \n      decoder.startDecodingSpeech {\n          \n          if let hyp: Hypotesis = $0 {\n              println(hyp)\n          } else {\n              // Can't decode any speech because an error\n          }\n      }\n  } else {\n      // Handle Decoder() fail\n  }\n} else {\n  // Handle Config() fail  \n}\n\n//At some point in the future stop listen to the mic\ndecoder.stopDecodingSpeech()\n\n```\n\n## Installation\n\nThe easiest way to integrate `TLSphinx` is using [Carthage] or a similar method to get the framework bundle. This lets you integrate the framework and the `Sphinx` module without _magic_.\n\n#### Carthage\n\nIn your `Cartfile` add a reference to the last version of `TLSphinx`:\n````\ngithub \"Tryolabs/TLSphinx\" ~\u003e 0.0.4\n````\n\nThen run `carthage update`, this should fetch and build the last version of `TLSphinx`. Once it's done, drag the _TLSphinx.framewok_ bundle to the XCode _Linked Frameworks and Libraries_. You must tell XCode where to find `Sphinx` module that is located in the Carthage checkout. To do so:\n- add `$(SRCROOT)/Carthage/Checkouts/TLSphinx/Sphinx/include` to _Header Search Paths_ recursive\n- add `$(SRCROOT)/Carthage/Checkouts/TLSphinx/Sphinx/lib` to _Library Search Paths_ recursive\n- in _Swift Compiler - Search Paths_ add `$(SRCROOT)/Carthage/Checkouts/TLSphinx/Sphinx/include` to _Import Paths_\n\n#### Manual\n\nDownload the project from this repository and drag the _TLSpinx_ project to your XCode project. If you encounter any errors about missing headers and/or libraries for _Sphinx_ please add the `Spinx/include` directory to your header search path and `Sphinx/lib` to the library search path and mark it as `recursive`.\n\n## Author\n\nBrunoBerisso, bruno@tryolabs.com\n\n## License\n\nTLSphinx is available under the MIT license. See the LICENSE file for more info.\n\n[CMU Sphinx]: http://cmusphinx.sourceforge.net/\n[Pocketsphinx]: http://cmusphinx.sourceforge.net/wiki/tutorialpocketsphinx\n[sphinx base]: http://sourceforge.net/projects/cmusphinx/files/sphinxbase/5prealpha/\n[Clang module]: http://clang.llvm.org/docs/Modules.html\n[Sphinx docs]: http://cmusphinx.sourceforge.net/wiki/\n[Tryolabs Blog]: http://blog.tryolabs.com/\n[Carthage]: https://github.com/Carthage/Carthage\n","funding_links":[],"categories":["Software"],"sub_categories":["Utilities"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcmusphinx%2FTLSphinx","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcmusphinx%2FTLSphinx","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcmusphinx%2FTLSphinx/lists"}