whisper_onnx_stt 0.0.1 copy "whisper_onnx_stt: ^0.0.1" to clipboard
whisper_onnx_stt: ^0.0.1 copied to clipboard

A Flutter plugin for offline Speech-to-Text inference using Whisper models exported to ONNX format. Runs on the highly optimized C/C++ sherpa-onnx framework.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:whisper_onnx_stt/whisper_onnx_stt.dart';
import 'package:file_picker/file_picker.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatefulWidget {
  const MyApp({super.key});

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  final _whisperPlugin = WhisperOnnxStt();
  String _status = 'Idle';
  double _downloadProgress = 0.0;
  String? _selectedFilePath;

  @override
  void initState() {
    super.initState();
  }

  Future<void> _initModel() async {
    setState(() => _status = 'Downloading/Initializing Model...');
    try {
      await _whisperPlugin.ensureModelDownloaded(
        'http://localhost:8000', // Example fallback link
        onProgress: (fileName, progress) {
          setState(() {
            _status = 'Downloading $fileName...';
            _downloadProgress = progress;
          });
        },
      );
      setState(() => _status = 'Model Ready');
    } catch (e) {
      setState(() => _status = 'Error initializing: $e');
    }
  }

  Future<void> _pickAndTranscribeMedia() async {
    final result = await FilePicker.platform.pickFiles(
      type: FileType.media,
      allowMultiple: false,
    );

    if (result != null && result.files.single.path != null) {
      setState(() {
        _selectedFilePath = result.files.single.path!;
        _status = 'Transcribing $_selectedFilePath...';
      });

      try {
        final text = await _whisperPlugin.transcribeMedia(
          _selectedFilePath!,
          language: 'it', // Force italian testing as user requested
        );
        setState(() => _status = 'Transcription:\n$text');
      } catch (e) {
        setState(() => _status = 'Error transcribing: $e');
      }
    } else {
      setState(() => _status = 'File picking aborted by user');
    }
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(title: const Text('Whisper ONNX Example')),
        body: Center(
          child: Padding(
            padding: const EdgeInsets.all(16.0),
            child: SingleChildScrollView(
              child: Column(
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  Text('Status: $_status', textAlign: TextAlign.center),
                  if (_downloadProgress > 0 && _status.contains('Downloading'))
                    LinearProgressIndicator(value: _downloadProgress),
                  const SizedBox(height: 20),
                  ElevatedButton(
                    onPressed: _initModel,
                    child: const Text('Download Models & Init'),
                  ),
                  const SizedBox(height: 10),
                  ElevatedButton(
                    onPressed: _pickAndTranscribeMedia,
                    child: const Text('Pick Media (Audio/Video) & Transcribe'),
                  ),
                ],
              ),
            ),
          ),
        ),
      ),
    );
  }
}
0
likes
150
points
60
downloads

Publisher

unverified uploader

Weekly Downloads

A Flutter plugin for offline Speech-to-Text inference using Whisper models exported to ONNX format. Runs on the highly optimized C/C++ sherpa-onnx framework.

Homepage
Repository (GitHub)

Documentation

API reference

License

MIT (license)

Dependencies

dio, ffmpeg_kit_flutter_new, flutter, flutter_lints, path_provider

More

Packages that depend on whisper_onnx_stt

Packages that implement whisper_onnx_stt