قالب وردپرس درنا توس
Home / IOS Development / Natural Language Processing and Speech Recognition in IOS

Natural Language Processing and Speech Recognition in IOS



Natural Language Processing (NLP) is a field of artificial intelligence (AI) and Computational Linguistics (CL) that deals with the interaction between computers and human natural languages. NPL is related to the Human-Computer Interaction (HCI) area and the ability of a computer program to understand human speech as it is spoken.

Speech Recognition (SR) is a subset of computational linguistics that develops methods and technologies that enable recognition and translation of spoken language to text via computers.

The development of NLP and SR applications is challenging because computers traditionally require people to talk to them in a programming language that is precise, unique and highly structured. Let's see what iOS 1

0 currently offers for these technologies.

Linguistic tags

NSLinguisticTagger is a class of the foundation's framework. Introduced with iOS 5, this class can be used to segment text in natural language and mark it with information, such as parts of speech. It may also mark languages, script, stamp form words, etc.

Combined with the new Voice framework (available in IOS 10), the linguistic tagger can get recognition of live and predefined speeches and can receive transcripts, alternatives interpretations and confidentiality levels.

To use the language tagger, create an instance of NSLinguisticTagger using the init (tagSchemes: options :) method. This init requires a variety of linguistic words and a set of options (such as omitting white spaces, punctuation, or joining in names).

API provides many linguistic system schemes: NSLinguisticTagSchemeTokenType NSLinguisticTagSchemeLexicalClass NSLinguisticTagSchemeNameType NSLinguisticTagSchemeNameTypeOrLexicalClass NSLinguisticTagSchemeLemma NSLinguisticTagSchemeLanguage and NSLinguisticTagSchemeScript . Each of these tags gives other information related to the element in a sentence.

Let's make a small example. Suppose we will analyze the following sentence:

Do you know about the legendary iOS training in San Francisco delivered by InvasiveCode? [19659000] Here is the source code:

This source code generates the following result :

Since speech recognition is a network-based service, some boundaries are enforced by Apple. In this way, the service may remain freely available for all apps. Individual devices may be limited in the number of perceptions that can be performed per day, and a single app can be spread globally, based on the number of requests it does per day. For these reasons, your application must be prepared to handle the errors as a result of reaching speech recognition limits.

Mix NPL and Voice Recognition

Let's start integrating speech recognition frame into a new app called YourSpeech ]. Create a new single viewer. Open Info.plist file and add "Privacy - Voice Recognition Use Description" or NSSpeechRecognitionUsageDescription key. Then you provide a phrase that explains users how to use speech recognition in your app. Since we are going to use the microphone, we must also request permission to access the microphone. Then add "Privacy - Use of Microphone Usage" or the key NSMicrophoneUsageDescription and provide a sentence explaining why your app wants to access the microphone.

Open the ViewController.swift file and add Import Languages ​​ to import the voice module. In the same display controls, we added the following property:

Here I install SFSpeechRecognizer to U.S. English. Then I set the viewer as the voice recognition representative. If speech recognition can not be initialized, returns zero . Add also SFSpeechRecognizerDelegate protocol near the class name:

Let's also add the following withdrawals for a button that we will use to start voice recording:

In the method viewDidLoad () you can add the following lines to print spoken languages ​​supported by speech recognition: