How to know AVSpeechSynthesizer speech finish in iOS objective c? - ios

I have play pdf file text-to-speech. I have a converted pdf to string page by page. Add all page string in NSMutableArray(EX:- 150 pages pdf , add first index - first page string ). How to get the first page string is over and speaking finish ?. And speak second page string ? I have searched in Google but I didn't find anything. Any help is appreciated.

You don't have to think about page unit.
You have to think about utterance.
Any amount of text you send to the speakUtterance method,
and AVSpeechSynthesizer finishes speaking,
the following delegate method called.
speechSynthesizer:(AVSpeechSynthesizer *)synthesizer
didFinishSpeechUtterance:(AVSpeechUtterance *)utterance;
So inside the delegate method, you have to call speakUtterance method again.
But in usual case, a few words or sentences(normally one sentence) will be sent to AVSpeechSynthesizer. == call speakUtterance
Then if speaking finishes, inside the delegate method, logic begins to start next sentence or word.
It's all I can tell you.

Related

Grab HTML from WKWebView using evaluateJavascript and then store it in a variable (using Swift)

I have users logging into a website using a WKWebView after which I want to parse the HTML of the page. I am very much new to Swift/iOS Development (just learning things as I go along). I know the id of the HTML tag I am trying to grab the innerHTML of (the id is "dataGrid") and would like to store the string in a variable called htmlString. I have the following code:
var htmlString = "initial value"
webView.evaluateJavaScript("document.getElementById('dataGrid').innerHTML.toString()",
completionHandler: { (html: Any?, error: Error?) in htmlString = html as! String})
print(htmlString)
Evidently this doesn't work - the last print statement just prints "initial value". Just so you know, I am basing my code off of the method described in another StackOverflow post (Get HTML from WKWebview in Swift). In the one, the completion handler has a print statement, which actually works in printing the HTML. However, I don't really understand completion handlers, which makes sense considering I haven't really had much experience with Swift yet, but it also means I don't know how to adapt the code in that post for my own purposes. I would really appreciate it if someone could direct me in the right direction so I can store the HTML of the page as a string in a variable that I can mutate later. Thank you!
The value of htmlString is "initial value" because the block is executed after the print statement is getting executed!
If you do print the htmlString inside the block you can see the actual value. You have to do your task inside the completion block. Also the completion block will be executed in the main thread so you need to make sure that you don't block the main thread.

How to hide Characters when Call Objective-C

I have a URL for conference call from iPhone,
tel:1600123456,,,,,,1234#
This is the conference call number followed by the Passcode.
While calling the whole number and characters are displayed.
How can I hide the ',,' in the call.
That's managed by the system. I don't believe there's any way to override it.

AVSpeechUtterance completion handler

How do I set a completion event on the SpeakUtterance(utterance) function in Swift? I need this so that my speech is neither interrupted nor interrupting.
Have you looked at the header (or generated Swift interface) for AVSpeechSynthesizer? Or its documentation? Looks pretty straightforward there...
Set an instance of one of your classes as the delegate of the speech synthesizer.
In that class, implement the speechSynthesizer(_:didFinishSpeechUtterance:) method. It'll be called whenever an utterance finishes speaking.
There's no step three.

UILexicon in Objective-C

How do you use UILexicon in Objective-C? I find the documentation Apple provides is extremely unhelpful.
What does it do? Does it return a dictionary or proper spellings of words? Or do I provide a word like "hellllo" and it matches it with the proper spelling "Hello" and returns that as a string?
Any help would be appreciated.
requestSupplementaryLexiconWithCompletion:
Here's my error report, but obviously I'll have errors because I'm completely guessing how to use the function, no clue what goes inside the block statement (because the docs (at the time) don't say! (Beta 4 docs)) Hahahah!
I've never used this feature, but a quick web search for "UILexicon" landed me in Apple's documentation; reading and following links from there filled in the picture pretty quick.
App Extension Programming Guide has a quick explanation of what lexicons are for:
Every custom keyboard (independent of the value of its RequestsOpenAccess key) has access to a basic autocorrection lexicon through the UILexicon class. Make use of this class, along with a lexicon of your own design, to provide suggestions and autocorrections as users are entering text.
Clicking the UILexicon link on that page took me to the reference doc for that class, which explains that it's a read-only list of Apple-provided term pairs. Each of its entries is a UILexiconEntry object -- the docs for that class say it provides a userInput (what the user typed, e.g. "ipad") and a documentText (what to substitute for it, e.g. "iPad"). Since those classes are read-only, it follows that they're probably not a way for you to provide your own autocorrection pairs -- as stated in the docs, they're for supplementing whatever autocorrection system you implement.
At this point, I don't even have to look at the doc for requestSupplementaryLexiconWithCompletion: to get a good idea how to use it: just the declaration tells me:
It's a method on UIInputViewController, the class I'd have to subclass to create a custom keyboard. Somewhere in that subclass I should probably call it on self.
Its return type is void, so I can't get a lexicon by assigning the result of a requestSupplementaryLexiconWithCompletion call to to a variable.
It calls the block I provide, passing me a UILexicon object as a parameter to that block.
It's got words like "request" and "completionHander" in it, so it'll probably do something asynchronous that takes awhile, and call that block when it's done.
So, I'm guessing that if I were writing a custom keyboard, I'd call this method early on (in viewDidLoad, perhaps) and stash the UILexicon it provides so I can refer to it later when the user is typing. Something like this:
#property UILexicon *lexicon;
- (void)viewDidLoad {
[super viewDidLoad];
[self requestSupplementaryLexiconWithCompletion:^(UILexicon *lexicon){
self.lexicon = lexicon;
}];
}
Because it's unclear how long requestSupplementaryLexiconWithCompletion will take to complete, any place where I'm using self.lexicon I should check to see if it's nil.
Back in the App Extension Programming Guide, it lists "Autocorrection and suggestion" under "Keyboard Features That iOS Users Expect", right before saying:
You can decide whether or not to implement such features; there is no dedicated API for any of the features just listed
So it sounds like autocorrection is something you have to do yourself, with your own UI that's part of the view presented by your UIInputViewController subclass. The API Quick Start for Custom Keyboards section in the programming guide seems to hint at how you'd do that: use documentContextBeforeInput to see what the user has recently typed, deleteBackward to get rid of it, and insertText: to insert a correction.

Debugging FBPlacePickerViewController loaddata method

I want to use [FBPlacePickerViewController loadData], and do some logic on the data received, before using the view.
How can I see the location information received in the loadData method?
You may look into using the FBPlacePickerDelegate: https://developers.facebook.com/docs/reference/ios/3.1/protocol/FBPlacePickerDelegate
It's not quite clear what you want to do, but if you're looking to filter the places, you can check out the placePickerViewController:shouldIncludePlace: delegate method.

Resources