nativemind_copilot_media 0.2.0
nativemind_copilot_media: ^0.2.0 copied to clipboard
Native media for nativemind_copilot: microphone recording, speech recognition, text-to-speech and file / photo / camera picking on plugins.
nativemind_copilot_media #
Native media for nativemind_copilot: microphone recording, on-device
speech recognition, text to speech and file / photo / camera picking. The package implements the copilot's
voice, speech and attachment ports on plugins (record, speech_to_text, flutter_tts, file_picker, image_picker).
The base nativemind_copilot stays plugin-free: it ships the ports, browser implementations (package:web) and fakes.
Add this package only to apps that need voice and attachments on Android, iOS or desktop.
| Port (nativemind_copilot) | Implementation here | Plugin |
|---|---|---|
NmAudioRecorder + NmAudioRecorderControls |
NmRecordAudioRecorder: Opus / AAC by platform, temp file → bytes, level 0..1, cancel |
record |
NmVoiceInput |
NmDeviceVoiceInput: platform recogniser, partial results, locale, denied / unavailable |
speech_to_text |
NmSpeechOutput |
NmTtsSpeechOutput: speak / stop, speaking stream, language from the locale, rate |
flutter_tts |
NmAttachmentPicker |
NmPluginAttachmentPicker: files, photo library, camera → NmAttachmentDraft |
file_picker, image_picker |
Install #
dependencies:
nativemind_copilot: ^2.0.0
nativemind_copilot_media: ^0.2.0
Use #
NmCopilotMedia gives ready-made settings. On the web it returns the copilot's browser implementations
(nmDefaultVoiceInput, nmDefaultSpeechOutput, nmDefaultAttachmentPicker, nmDefaultAudioRecorder), so a web build
behaves as without this package.
import 'package:nativemind_copilot/nativemind_copilot.dart';
import 'package:nativemind_copilot_media/nativemind_copilot_media.dart';
final controller = NmCopilotController(
NmCopilotConfig(
engine: engine,
voice: NmCopilotMedia.voice(engine: engine), // device recogniser; NmVoiceMode.server: record + engine.transcribe
attachments: NmCopilotMedia.attachments(maxBytes: 5 << 20),
voiceAssistant: NmCopilotMedia.assistant(), // voice mode, replies spoken with flutter_tts
),
);
The single implementations are available too: NmCopilotMedia.recorder(), voiceInput(engine:), speechOutput(),
picker(), or the classes directly (NmTtsSpeechOutput(locale: 'ru-RU', rate: 0.5),
NmDeviceVoiceInput(onDevice: true), NmPluginAttachmentPicker(sources: {NmAttachmentSource.files}) …).
Testing. Every class takes its plugin through a small interface (NmRecordBackend, NmRecordingFiles,
NmSpeechBackend, NmTtsBackend, NmPickerBackend) defaulting to the real plugin; pass a fake in unit tests, no
platform channels needed. Constructing the classes touches no plugin until first use.
Notes. Picked files are read into memory (file_picker 13 has no withData; PlatformFile.readAsBytes() is used);
the size and count limits are checked by the copilot (NmAttachmentPolicy, the chip shows «too large»). Recordings go
to the system temp directory and are deleted after reading. Platform recognisers may use the vendor's servers unless
onDevice: true.
Permissions #
| Platform | Needed for | Entry |
|---|---|---|
Android (AndroidManifest.xml) |
recording, recognition | <uses-permission android:name="android.permission.RECORD_AUDIO"/> |
| Android | camera | <uses-permission android:name="android.permission.CAMERA"/> (+ <uses-feature android:name="android.hardware.camera" android:required="false"/>) |
| Android | online recognition, the copilot | <uses-permission android:name="android.permission.INTERNET"/> |
| Android 11+ | finding the recogniser and TTS engine | <queries> with intents android.speech.RecognitionService and android.intent.action.TTS_SERVICE |
iOS (Info.plist) |
recording, recognition | NSMicrophoneUsageDescription |
| iOS | recognition | NSSpeechRecognitionUsageDescription |
| iOS | camera | NSCameraUsageDescription |
| iOS | photo library | NSPhotoLibraryUsageDescription |
macOS (*.entitlements) |
recording | com.apple.security.device.audio-input = true |
| macOS | camera (if used) | com.apple.security.device.camera = true |
| macOS | picking files | com.apple.security.files.user-selected.read-only = true |
| macOS | online recognition, the copilot | com.apple.security.network.client = true |
macOS (Info.plist) |
recording, recognition | NSMicrophoneUsageDescription, NSSpeechRecognitionUsageDescription |
| Web | microphone | the browser asks; HTTPS required |
The example app (example/) carries the Android and iOS entries.
Platform support #
| Android | iOS | macOS | Windows | Linux | Web | |
|---|---|---|---|---|---|---|
NmRecordAudioRecorder |
✓ (Opus/Ogg, AAC) | ✓ (AAC/m4a) | ✓ (AAC/m4a) | ✓ | ✓ (Opus/Ogg, WAV) | copilot's NmWebAudioRecorder |
NmDeviceVoiceInput |
✓ | ✓ | ✓ | ✓ | — (factory returns null) | copilot's NmWebSpeechInput / server |
NmTtsSpeechOutput |
✓ | ✓ | ✓ | ✓ | — (factory returns null) | copilot's NmWebSpeechOutput |
NmPluginAttachmentPicker |
files, images, camera | files, images, camera | files, images | files, images | files, images | copilot's NmWebAttachmentPicker |
License #
NativeMindNONC (LICENSE). Plugin licenses: NOTICE. Who wrote what: PROVENANCE.md.