Mercurial
comparison dictation/main.py @ 282:6bd4a3990696 default tip
Add cross-platform canvas orchestration and typed composer
Enable native ARM dependencies, macOS Copilot orchestration, portable service supervision, CPU dictation, and a shared N-key speak-or-type composer.
Co-authored-by: Copilot <[email protected]>
Copilot-Session: f68442b1-fa8f-46a0-9689-81710613bbd4
| author | MrJuneJune <me@mrjunejune.com> |
|---|---|
| date | Thu, 20 Aug 2026 20:45:25 -0700 |
| parents | 78699f810817 |
| children |
comparison
equal
deleted
inserted
replaced
| 281:c57149ad216e | 282:6bd4a3990696 |
|---|---|
| 35 | 35 |
| 36 | 36 |
| 37 def preflight(config: DictationConfig) -> None: | 37 def preflight(config: DictationConfig) -> None: |
| 38 import ctranslate2 | 38 import ctranslate2 |
| 39 | 39 |
| 40 compute_types = sorted(ctranslate2.get_supported_compute_types("cuda")) | 40 compute_types = sorted( |
| 41 ctranslate2.get_supported_compute_types(config.device) | |
| 42 ) | |
| 41 if config.compute_type not in compute_types: | 43 if config.compute_type not in compute_types: |
| 42 raise RuntimeError( | 44 raise RuntimeError( |
| 43 f"{config.compute_type} is unsupported on CUDA; " | 45 f"{config.compute_type} is unsupported on {config.device}; " |
| 44 f"available: {', '.join(compute_types)}" | 46 f"available: {', '.join(compute_types)}" |
| 45 ) | 47 ) |
| 46 result = { | 48 result = { |
| 47 "cudaDeviceCount": ctranslate2.get_cuda_device_count(), | 49 "device": config.device, |
| 48 "computeTypes": compute_types, | 50 "computeTypes": compute_types, |
| 49 "selectedComputeType": config.compute_type, | 51 "selectedComputeType": config.compute_type, |
| 50 "modelDir": str(config.model_dir), | 52 "modelDir": str(config.model_dir), |
| 51 "modelPresent": (config.model_dir / "model.bin").is_file(), | 53 "modelPresent": (config.model_dir / "model.bin").is_file(), |
| 52 } | 54 } |
| 53 if result["cudaDeviceCount"] < 1: | 55 if config.device == "cuda": |
| 56 result["cudaDeviceCount"] = ctranslate2.get_cuda_device_count() | |
| 57 if config.device == "cuda" and result["cudaDeviceCount"] < 1: | |
| 54 raise RuntimeError("CTranslate2 did not detect a CUDA device") | 58 raise RuntimeError("CTranslate2 did not detect a CUDA device") |
| 55 print(json.dumps(result, indent=2)) | 59 print(json.dumps(result, indent=2)) |
| 56 | 60 |
| 57 | 61 |
| 58 async def transcribe_file(config: DictationConfig, path: Path) -> None: | 62 async def transcribe_file(config: DictationConfig, path: Path) -> None: |
| 59 from dictation.transcriber import FasterWhisperTranscriber | 63 from dictation.transcriber import FasterWhisperTranscriber |
| 60 | 64 |
| 61 transcriber = FasterWhisperTranscriber( | 65 transcriber = FasterWhisperTranscriber( |
| 62 config.model_dir, | 66 config.model_dir, |
| 67 config.device, | |
| 63 config.compute_type, | 68 config.compute_type, |
| 64 ) | 69 ) |
| 65 try: | 70 try: |
| 66 from av import open as av_open | 71 from av import open as av_open |
| 67 from av.audio.resampler import AudioResampler | 72 from av.audio.resampler import AudioResampler |