Smart Clock (Voice Control)

Last updated


Voice-controlled 7-segment smart clock (zh-TW Web Speech API) on QuickUI 0.6.2: shows time, date, year, seconds and runs spoken countdowns.

Overview


ItemValue
Created2024-12-20
CategoryApp & Platform Examples
HTML filesindex.html
Sourcetarget/20241220

Preview


Smart Clock (Voice Control) screenshot
Open the example in a new tab

Page Sections


SectionDescription
Clock (#timer.timer)Four div.number digits of 7 span segments each plus a div.colon; digits render from data-value.
Hint (section.bottom)Lists supported commands: 顯示當前日期/年份/時間/秒數、計時xx分鐘、計時xx秒.

Interactions


  • In QUI when.rendered: when webkitSpeechRecognition is available, start continuous zh-TW recognition with interim results; otherwise show an alert.
  • onresult debounces 500ms, then matches keywords: 現在/當前時間 → setTime, 現在/當前年份 → setYear, 現在/當前日期 → setDate, 現在/當前秒數 → setSec (each refreshed every 1s by setInterval).
  • '計時N分鐘' / '計時N秒' parsed by regex start setCountDown; '停止' calls setStop (all digits '-'); other speech of 2+ chars and onerror/onend show a face (setFace: eyes + mouth).

Dependencies


NameVersionSource
Font Awesome Free6.5.2https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@6.5.2/css/all.min.css
QuickUI (@pardnchiu/quickui)0.6.2https://cdn.jsdelivr.net/npm/@pardnchiu/quickui@0.6.2/dist/QuickUI.js
Noto Sans / Noto Sans TC (font-family only)-declared in SCSS (index.scss / _init.scss); no font stylesheet linked
Web Speech API (webkitSpeechRecognition)-browser built-in

Styling


ItemValue
SCSS entrysass/index.scss
Output CSScss/index.css
Partials_init.scss, function/_hsbTohsl.scss

_init holds the reset; function/_hsbTohsl provides hsb()/hsba(). index.scss sizes the clock with --width: calc(100vw / 40), --height and --triHeight, and toggles segment opacity per [data-value] (0-9, '-', eye, mouth/none for the colon).
  1. cd target/20241220
  2. npx sass sass/index.scss css/index.css --no-source-map || exit 1

Techniques


  • Pure-CSS 7-segment digits: span:nth-child segments shown via [data-value] attribute selectors; viewport-relative sizing with CSS vars.
  • JS writes element.dataset.value only; no DOM rebuilding.
  • Web Speech API with debounce (setTimeout) and setInterval refresh; regex extraction of countdown length.

External Assets




中文