GithubHelp home page GithubHelp logo

bhvk121 / speechkitmanager Goto Github PK

View Code? Open in Web Editor NEW

This project forked from zaidpathan/speechkitmanager

0.0 2.0 0.0 153 KB

iOS 10 SpeechKit framework made easy, πŸŽ™to πŸ”  && πŸ“Ό to πŸ” 

License: MIT License

Ruby 5.05% Objective-C 4.02% Shell 47.28% Swift 43.65%

speechkitmanager's Introduction

SpeechKitManager

[![CI Status](http://img.shields.io/travis/Zaid Pathan/SpeechKitManager.svg?style=flat)](https://travis-ci.org/Zaid Pathan/SpeechKitManager) Version License Platform

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Requirements

XCode : 8.0 +

iOS : 10.0 +

Swift : 3.0 +

Device : Real iOS device required

Installation

SpeechKitManager is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod "SpeechKitManager"

Usage

Note : Add NSMicrophoneUsageDescription(For Live Speech to Text only) and NSSpeechRecognitionUsageDescription to info.plist.

Initialize SpeechKitManager and your audio file path and URL
import SpeechKitManager

fileprivate var speechKitManager:SpeechKitManager?
let audioPath = Bundle.main.path(forResource: "testAudio", ofType: "m4a")   //For audio file to text
var audioURL:URL?                                                           //For audio file to text

override func viewDidLoad() {
    super.viewDidLoad()
    speechKitManager = SpeechKitManager()
}
Authorize Speech Recognition and handle it.
speechKitManager?.requestSpeechRecognizerAuth { (authStatus) in
    /*
    The callback may not be called on the main thread. Add an
    operation to the main queue to update the record button's state.
    */
    OperationQueue.main.addOperation {
        switch authStatus {
            case .authorized:
                self.recognizeAudio()
                print("requestSpeechRecognizerAuth authorized")
            case .denied:
                print("requestSpeechRecognizerAuth denied")
            case .restricted:
                print("requestSpeechRecognizerAuth restricted")
            case .notDetermined:
                print("requestSpeechRecognizerAuth notDetermined")
            }
        }
    }

1. Audio file to Text

Recognize Audio
fileprivate func recognizeAudio(){
    if let path = self.audioPath{
        self.speechKitManager?.recognizeAudio(atURL: URL(fileURLWithPath: path), resultHandler: { (result, error) in
            if let result = result{
                //Audio to Text fall here
                debugPrint(result.bestTranscription.formattedString)
            }else if let error = error{
                debugPrint(error.localizedDescription)
            }
        })
    }else{
        debugPrint("no path found")
    }
}

2. Live Speech to Text

Request Microphone access and handle it.
fileprivate func authorizeMicAccess(){
    speechKitManager?.requestMicAuth({ (granted) in
        if granted{
        //Mic access granted start recognition
        self.recognize()
        }else{
            debugPrint("Microphone permission required")
        }
    })
}
Recognize live speech. πŸ“’
fileprivate func recognize(){
    speechKitManager?.record(resultHandler: { (result, error) in
        var isFinal = false

        if let result = result {
            //User speech will fall here to text
            debugPrint(result.bestTranscription.formattedString)
            isFinal = result.isFinal
        }

        if error != nil || isFinal {
            self.speechKitManager?.stop()
        }
    })
}

Awesome πŸ™Œ, look at the demo project - everything explained here is implemented in that.

Author

Zaid Pathan, [email protected]

License

SpeechKitManager is available under the MIT license. See the LICENSE file for more info.

speechkitmanager's People

Contributors

zaidpathan avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.