Skip to main content

alkove 0.1.1 copy "alkove: ^0.1.1" to clipboard
alkove: ^0.1.1 copied to clipboard

Alkove for Flutter: Focus, Cue, Spot, Timbre and Lex on the device, over the native Android and iOS SDKs.

example/lib/main.dart

import 'dart:async';

import 'package:alkove/alkove.dart';
import 'package:material_ui/material_ui.dart';

void main() => runApp(const MaterialApp(home: Demo()));

// an agent input and a wake listener, each with its status, mode and last events
class Demo extends StatefulWidget {
  const Demo({super.key});

  @override
  State<Demo> createState() => _DemoState();
}

class _DemoState extends State<Demo> {
  AlkoveInput? _input;
  StreamSubscription<AlkoveEvent>? _sub;
  final _seen = <String>[];
  String? _error;

  Future<void> _open(Future<AlkoveInput> Function() start) async {
    await _close();
    setState(() => _error = null);
    try {
      final input = await start();
      _sub = input.events.listen((e) => setState(() {
            _seen.insert(0, describe(e));
            if (_seen.length > 12) _seen.removeLast();
          }));
      setState(() => _input = input);
    } on AlkoveError catch (e) {
      setState(() => _error = '${e.code}: ${e.message}');
    }
  }

  Future<void> _close() async {
    await _input?.close();
    await _sub?.cancel();
    if (mounted) setState(() => _input = null);
  }

  @override
  Widget build(BuildContext context) {
    final i = _input;
    return Scaffold(
      appBar: AppBar(title: const Text('Alkove')),
      body: ListView(padding: const EdgeInsets.all(16), children: [
        Text(i == null ? 'off' : '${i.status.name} ${i.mode.wire}', key: const Key('state')),
        if (_error != null) Text(_error!, key: const Key('error')),
        Wrap(spacing: 8, children: [
          ElevatedButton(key: const Key('agent'), onPressed: () => _open(() => AgentInput.start(const AgentOptions(langs: ['fr', 'en'], trace: true))), child: const Text('Agent')),
          ElevatedButton(
            key: const Key('wake'),
            onPressed: () => _open(() async => WakeListener.start(WakeOptions([await Spot.compile('alkove', lang: ['fr'])], context: 'anywhere', trace: true))),
            child: const Text('Wake word'),
          ),
          ElevatedButton(key: const Key('stop'), onPressed: _close, child: const Text('Stop')),
        ]),
        for (final s in _seen) Text(s),
      ]),
    );
  }
}

String describe(AlkoveEvent e) => switch (e) {
      StatusChange(:final status) => 'status ${status.name}',
      ModeChange(:final mode) => 'mode ${mode.wire}',
      SpeechStart(:final start) => 'speech from ${start.toStringAsFixed(2)} s',
      SpeechEnd(:final start, :final end) => 'speech ${start.toStringAsFixed(2)} to ${end.toStringAsFixed(2)} s',
      Wake(:final word, :final score) => 'wake $word ${score.toStringAsFixed(2)}',
      Language(:final lang, :final p) => 'language $lang ${p.toStringAsFixed(2)}',
      Command(:final id, :final phrase) => 'command $id: $phrase',
      Diag(:final code) => 'diag $code',
      _ => e.runtimeType.toString(),
    };
0
likes
160
points
62
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

Alkove for Flutter: Focus, Cue, Spot, Timbre and Lex on the device, over the native Android and iOS SDKs.

Homepage
Repository (GitHub)
View/report issues
Contributing

License

Apache-2.0 (license)

Dependencies

flutter

More

Packages that depend on alkove

Packages that implement alkove