Back to Moonshine

Dialog Flow Example

examples/macos/DialogFlow/README.md

0.1.01.3 KB
Original Source

Dialog Flow Example

A Swift command-line assistant that walks you through setting up wifi by voice, mirroring the web dialog-flow demo and the Python dialog_flow.py script.

DialogFlow owns the speech-to-text, intent, and text-to-speech engines, so the interesting part of the program is the flow itself — ordinary async code that asks a question and gets an answer back:

swift
let ssid = try await d.ask("What's the name of your wifi network?")
guard try await d.confirm("I heard \(ssid). Is that right?") else { ... }

Building

bash
cd examples/macos/DialogFlow
swift build

Running

bash
# Speak to it (asks for microphone access the first time)
swift run DialogFlow

# Type the answers instead, for machines without a microphone
swift run DialogFlow --text

Say (or type) "set up wifi" to start the flow. Two commands work at any point without being registered, because DialogFlow provides them:

  • "cancel" abandons the flow
  • "start over" runs it again from the top

Notes

  • The speech, intent, and voice models are downloaded on first run into ~/Library/Caches/MoonshineModels/ and reused afterwards. The first run fetches roughly a gigabyte, so give it a minute.
  • The microphone is muted while the assistant is speaking, so it does not transcribe itself.