SpeechInjector 1.1.0

SpeechInjector 1.1.0

Richard E.V. Simpson 维护。



  • Richard E.V. Simpson

由 Richard Simpson 开发的 SpeechInjector

联系方式: [email protected]

将语音命令应用于您的 IOS app 的最简单方法。

简单添加您想要程序响应的单词,然后对特定单词或单词组调用您想要响应的程序或函数。您可以根据需要创建任意数量的不同集合。您将很快拥有通过语音命令完全导航的应用程序!

安装

pod 'SpeechInjector','~> 1.1.0'

示例应用

示例应用程序可以在此处下载:https://github.com/revsimpson/SpeechInjector-Demo

如何使用?

以下是如何使用它的示例代码

import UIKit

class ViewController: UIViewController {

var injector : SpeechInjector!  // Allways initiate here not in viedDidLoad or anywhere else!!!

override func viewDidLoad() {
    super.viewDidLoad()
    
    // Setting up connectors...which are a set of words (add as much as you like) which when are being said
    // will perform the action you specify in the closure. PS Also keep in mind people do not say the words
    // as they should so you should take grammer errors into account. During debugging you will see what word
    // is captured when you say something.
    
    let connector1 = SpeechConnector(words: "hello","hi","good morning","hellu") {
        // do some kind of action
        print("connector1 action done") 
    }
    
    let connector2 = SpeechConnector(words: "next","forward") {
        // do some kind of action for instance transtion to another screen
        // or do something in the UI. Always refer to self within the closure
        // but code complition will let you know ;-)
        
        print("connector2 action done") 
    }
    
    let connector3 .... etc etc etc

   // When you made all your voice-commands add them to the SpeechInjector
   // You always send 'self' along with the init of the injector
   
   injector = SpeechInjector(connectors: [connector1,connector2, etc etc], vc: self)
   
   // Now place the button in you viewcontroller
   injector.placeSpeechButton()
}

}

如果您的按钮在应用中放置不正确,请在 viewDidAppear 中设置 injector.placeSpeechButton()

Plist

请将以下隐私设置添加到您的plist中,并告知用户为什么需要使用他们的麦克风和语音识别。

隐私 - 麦克风使用描述

隐私 - 语音识别使用描述

为SpeechInjector设置不同的初始化选项

您可以在初始化SpeechInjector时设置不同的选项

基本 :

SpeechInjector(connectors: [SpeechConnector], vc: UIViewController) <- 连接器和vc是必须的!

带有选项 :

有效

SpeechInjector(connectors: [connector1], vc: self, language: "nl-NL")

有效

SpeechInjector(connectors: [connector1,connector2,connector3], vc: self, language: "en-US")

有效

SpeechInjector(connectors: [connector1,connector2], vc: self)

无效

如果不使用某个属性,就不要将它设置为"nil"。所以您要么使用它,要么从初始化中删除它。

所以这是错误的

SpeechInjector(connectors: [connector1, connector2], vc: self, language: nil) <- 错误!!

或者

SpeechInjector(connectors: [connector1, connector2], vc: self, language: "") <- 错误!!

如果不使用属性,就将其全部留空!

有关语言代码的检查: https://gist.github.com/JamieMason/3748498

默认设置 SpeechInjector

如果不使用属性,则使用默认设置。

language = "nl-NL"(使用您自己的国家代码来捕捉您自己的语言!)

放置speechbutton及其默认设置

基本放置按钮的情况是您有一个SpeechInjector实例时,您调用

injector.placeSpeechButton()

将放置一个带有默认设置的按钮。您可以更改按钮的图像和按钮的tintcolor和elevation设置等。就像SpeechInjector初始化...只填写您想要使用的,不使用您不想要的,其余参数将应用默认设置。

这是placeSpeechButton的默认设置。

func placeSpeechButton(position : SpeechButtonLocation = .rightBottom, buttonColor: UIColor = UIColor(red:0.30, green:0.50, blue:0.70, alpha:1.0) , buttonRecordingColor :UIColor = UIColor(red:0.94, green:0.17, blue:0.18, alpha:1.0), buttonHeight:CGFloat = 60 , buttonWidth : CGFloat = 60, xOffset: CGFloat = 16, yOffset : CGFloat = 16, image : UIImage = UIImage(named: "speech")!, tintColor : UIColor = UIColor.white, elevationNormalState: CGFloat = 6.0, elevationHighlightedState : CGFloat = 12.0)

您可以通过如下方式调用,例如:

injector.placeSpeechButton(position: .leftBottom,yOffset: 39, elevationNormalState = 14)

或者

injector.placeSpeechButton() <--- 它将会使用所有默认值

您未填写的内容将获取默认值。按钮的标准图像是名为 speech 的 materialdesign 麦克风按钮,请确保您的项目中没有相同名称的图片。否则,您可以放置任何您想要的照片。但是……如果您不想使用它们,不要使用 nil 参数填充,因为这会导致错误,只需留下即可,它将正常工作。

设置位置后的额外偏移量

当您已在 placeSpeechButton 中设置了位置时,您仍然可以改变该位置的偏移量。

记住我们设置的按钮位置

injector.placeSpeechButton(postion: right.bottom)

您可以像这样向该函数添加偏移量

injector.placeSpeechButton(postion: right.bottom, xOffset: 20, yOffset : 35)

默认偏移量是 xOffset = 16 和 yOffset = 16)

暂时就这些…… !

如果您想捐款,我的地址如下

TRON (TRX) : TAo7ydaxqXu6bebuCUH2qEdhP6xP65E35K

BITCOIN (BTC) : 1AmjnkZsXuBmowGjw6gEyisdkYBPYhaD8z