Command Palette

Search for a command to run...

Hectal
Phase 11: Files, Images and Voice
AI Frontend · Exercise 4 of 5 PreviousNext
Intermediate

Cut an Answer into Spoken Sentences

Write speakable(text, min) that returns an array of sentences to speak. Split with Intl.Segmenter (locale "en", granularity: "sentence"), trim each piece, and join short pieces with the next one until the text is at least min characters, so Dr. is not spoken alone. Whatever is left at the end is the last item, even if it is short.

The page calls speakable(text, 24) when #run is clicked and lists each sentence as an <li> in #out. An empty text gives an empty list.

What Check tests

  1. Dr. stays with the name: two sentences
  2. Three long sentences stay three
  3. A short text is returned as one item
  4. An empty text gives an empty list

Stuck? One hint at a time

The solution unlocks after your first Check. Try first: that is where the learning happens.

Runs in your browser. Your code is saved here.

Your page

Press Run to see the page.

Console

Nothing logged yet.