-1

I saw this feature in many children apps where the word magnified when the reader read it. i want to know how it was achieved in swift here is an example:

https://youtu.be/Hv0In39r2so

I have no idea what I've to seach for to learn about it

Wen
  • 9
  • 6
  • There's no particular feature here. The app is almost certainly just drawing a box at the appropriate times. You need to track when various words occur in your audio, and draw boxes at those times. I don't expect any magic here. It's just code you need to write. This isn't a built-in feature of iOS. (The text also doesn't look magnified. It looks like they're just drawing a box around it.) – Rob Napier Feb 19 '21 at 20:56
  • Are you saying they do this manually?? For every word?? – Wen Feb 19 '21 at 20:59
  • 1
    It's not difficult to find a word and draw a box around it (using Text Kit). – matt Feb 19 '21 at 21:05
  • Speech segmentation is a topic you could research https://en.wikipedia.org/wiki/Speech_segmentation – Warren Burton Feb 19 '21 at 21:08
  • they may do this manually, or they may do this semi-automatically, or they may do this with voice recognition. I'm just saying there's no magical "highlight word as they're spoken" tool in iOS. You're going to have to develop an algorithm and write code to do it. Very often the best solution is to have people listen to the text and hit space bar for each word, and then use that to drive the timings. Devs tend to assume complicated solutions, when "throws humans at it" is how it's really done. – Rob Napier Feb 19 '21 at 21:30

1 Answers1

1

It's hard to be sure. in the example you linked it looks like it's drawing a highlighing rectangle with a drop shadow behind the text rather than magnifying it.

You could use attributed strings (NSAttributedString) to highlight each word in bold, for example. I'm not sure how you would synchronize the highlighting with the spoken text however. You might need to create an array of time indexes for the time when the audio begins speaking each word in the text, along with a range for each word to be highlighted. You could then apply bolding (or other styling changes) to one word at a time as each time index passes.

If you wanted to use a highlighting box as in the video you'd probably have to use CoreText. This link should get you started, but be warned that CoreText is complicated. It is not a beginner framework.

Duncan C
  • 128,072
  • 22
  • 173
  • 272
  • I don't see why there would be a need to drop down to the level of core text. Text Kit can do the boxes quite simply. – matt Feb 19 '21 at 21:05
  • @Matt, I haven't used Text Kit. Do you have an example you could link to? – Duncan C Feb 19 '21 at 21:26
  • Also, there's the non-stop crashing of TextKit that so often pushes me back to Core Text… but yes, TextKit could probably do it :D – Rob Napier Feb 19 '21 at 21:31
  • Is Text Kit Mac OS only? The system docs list it as AppKit, and seem to hint that it's Mac-specific. – Duncan C Feb 19 '21 at 21:35
  • No it migrated to iOS years ago. UITextView is a very thin Text Kit wrapper. – matt Feb 19 '21 at 21:58