iSphinx 1.2.0

iSphinx 1.2.0

测试已测试
语言语言 SwiftSwift
许可证 MIT
发布最后发布2018年1月
SPM支持SPM

icaksama 维护。



iSphinx 1.2.0

iSphinx

Creator
Travis
GitHub license
Code Size
Pod Version
Platform
Download Total
Docs


iSphinx 是基于 Pocketsphinx 引擎的离线语音识别 iOS 库。通过 Cocoapods 将语音识别功能添加到您的 iOS 应用程序中。iSphinx 为您的应用程序提供简单配置和实现,无需处理 Pocketsphinx 资产和配置。

功能

  • 高准确度
  • 支持 Swift 4 和 iOS 9 以上
  • 即时构建字典
  • 即时构建语言模型(Arpa 文件)
  • 即时构建 JSGF 语法
  • 支持 PCM 录音 16位/单声道小端(wav 文件)
  • 每个单词的得分系统(范围 0.0 - 1.0)
  • 检测不支持的单词
  • 基于关键词搜索拒绝未知词汇(OOV)
  • 说话人自适应(进行中)
  • 简单易用 & 快速!

预览

我尝试以不同的词序说话

Cocoapods

添加到 Podfile

pod 'iSphinx', '~> 1.2.0'

如何使用

添加请求权限

  • 在您的 Info.plist 中添加录音请求权限

添加监听器

首先,在您的类/ViewController 中实现 iSphinxDelegete

import iSphinx

class ViewController: UIViewController, iSphinxDelegete {
    var isphinx: iSphinx = iSphinx()

    override func viewDidLoad() {
        super.viewDidLoad()
        isphinx.delegete = self
    }
}

iSphinxDelegete有一些在您的类/ViewController必须实现的方法

func iSphinxDidStop(reason: String, code: Int) {
    if code == 500 { // 500 code for error
        print(reason)
    } else if code == 522 { // 522 code for timed out
        print(reason)
    } else if code == 200 { // 200 code for finish speech
        print(reason)
    }
}

func iSphinxFinalResult(result: String, hypArr: [String], scores: [Double]) {
    print("Full Result : \(result)")
    // NOTE :
    // [x] parameter "result" : Give final response with ??? values when word out-of-vocabulary.
    // [x] parameter "hypArr" : Give final response in original words without ??? values.

    // Get score from every single word. hypArr length equal with scores length
    for score in scores {
        print(score)
    }

    // Get array word
    for word in hypArr {
        print(word)
    }
}

func iSphinxPartialResult(partialResult: String) {
    print(partialResult)
}

func iSphinxUnsupportedWords(words: [String]) {
    var unsupportedWords = ""
    for word in words {
        unsupportedWords += word + ", "
    }
    print("Unsupported words : \(unsupportedWords)")
}

func iSphinxDidSpeechDetected() {
    print("Speech detected!")
}

准备语音识别

在使用之前,您需要准备语音识别。您可以在 onPreExecute 中添加新参数以增加准确度或性能。

isphinx.prepareISphinx(onPreExecute: { (config) in
    // You can add new parameter pocketshinx here
    self.isphinx.silentToDetect = 1.0
    self.isphinx.isStopAtEndOfSpeech = true
    // config.setString(key: "-parameter", value: "value")
}) { (isSuccess) in
    if isSuccess {
        print("Preparation success!")
    }
}

更新语言模型/语法

您可以在不中断的情况下即时更新词汇表、语言模型或 JSGF 语法。确保在更新词汇/语法之前删除标点符号。iSphinx 中默认要移除的标点是 (.), (,), (?), (!), (_), (-), (\), (:)

// Update vocabulary with language model from single string
isphinx.updateVocabulary(text: "YOUR VOCABULARIES!", oovWords: ["WORDS DISTRUBER", ...]) {
    print("Vocabulary updated!")
}

// Update vocabulary with language model from array string
isphinx.updateVocabulary(text: "YOUR VOCABULARIES!", oovWords: ["WORDS DISTRUBER", ...]) {
    print("Vocabulary updated!")
}

// Update vocabulary with JSGF Grammar from string
isphinx.updateGrammar(text: "YOUR GRAMMAR", oogWords: ["WORDS DISTRUBER", ...]) {
    print("Grammar updated!")
}

开始语音识别

您可以有或没有超时地开始语音识别。

// Start speech recognition with Timeout in seconds
isphinx.startISphinx(timeoutInSec: 10)

// Start speech recognition without Timeout
isphinx.startISphinx()

停止语音识别

您可以手动停止语音识别。

// Stop speech recognition manually.
isphinx.stopISphinx()

播放音频记录

确保在语音识别完成后播放音频记录。

isphinx.getRecorder().play {
    print("Play audio finish!")
}

注意:请参阅 iSphinxDemo 以获取详细信息。

MIT 许可证

Copyright (c) 2018 Saiful Irham Wicaksana

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.