-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutter-spec.txt
More file actions
1910 lines (1270 loc) · 42.3 KB
/
Copy pathutter-spec.txt
File metadata and controls
1910 lines (1270 loc) · 42.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
UTTER
Local Text-to-Speech CLI for Apple Silicon
Project Specification
Version: 1.0
Target platform: macOS on Apple Silicon, with Mac mini M4 as the primary development and validation machine
======================================================================
1. PROJECT SUMMARY
======================================================================
Utter is a local-first command-line text-to-speech tool for macOS.
Its primary purpose is simple:
text + selected built-in voice -> local speech synthesis -> audio file
Utter is not intended to be a full desktop application, voice editor, audio
workstation, or GUI product. It should be a focused developer utility that can
be used directly from Terminal and invoked programmatically from other apps.
Primary example:
utter speak "This is a flower." --voice Ryan -o flower.wav
The generated audio must be produced locally on Apple Silicon using Qwen3-TTS
through MLX acceleration. No cloud API should be required for synthesis after
the model has been downloaded.
The first implementation should prioritize:
- voice quality
- reliability
- predictable CLI behavior
- clean integration from other applications
- offline inference
- Apple Silicon performance
- a stable command-line contract
The first version should deliberately avoid unnecessary product complexity.
======================================================================
2. PRIMARY GOAL
======================================================================
Build a reliable CLI that allows a user or another application to:
1. Download/install the required TTS model.
2. List available built-in voice profiles.
3. Provide text.
4. Select one of the model's supported preset voices.
5. Generate speech locally.
6. Save the speech to a WAV file.
7. Receive predictable success/error output suitable for automation.
======================================================================
3. NON-GOALS FOR MVP
======================================================================
Do NOT build the following in the first MVP:
- GUI
- Tauri application
- SwiftUI application
- web UI
- HTTP API server
- database
- user accounts
- cloud synthesis
- billing
- authentication
- voice marketplace
- voice recording
- speech-to-text
- voice cloning
- custom reference-audio voices
- project/history library
- audio effects
- timeline editor
- waveform editor
- batch job scheduler
- background daemon
- streaming playback
- true real-time streaming synthesis
- plugin system
- automatic model switching
- automatic cloud fallback
- telemetry
- analytics
- crash reporting
- cross-platform support
These may be added later only if a real use case requires them.
======================================================================
4. TARGET ENVIRONMENT
======================================================================
Primary target:
- macOS
- Apple Silicon
- Mac mini M4
Initial development environment:
- Python 3.12
- MLX
- MLX-Audio
- Qwen3-TTS
- Hugging Face model artifacts/cache
- local filesystem
- WAV output
Utter should be developed and validated first on the Mac mini M4.
Do not optimize for Intel Macs.
Do not add CUDA, ROCm, DirectML, XPU, Windows, or Linux backend logic in MVP.
======================================================================
5. RECOMMENDED MODEL AND RUNTIME
======================================================================
Primary model:
Qwen3-TTS 1.7B CustomVoice
Primary runtime:
MLX-Audio + MLX/Metal
Recommended initial model artifact:
Qwen3-TTS 1.7B CustomVoice 8-bit MLX conversion
Reasoning:
- Qwen CustomVoice provides built-in preset speakers.
- The 1.7B model should be preferred over 0.6B because voice quality,
naturalness, prosody, robustness, and instruction following matter more than
minimizing model size.
- 8-bit MLX is the preferred starting point because it provides a practical
balance between model size, memory usage, load time, and quality.
- MLX is the appropriate acceleration layer for Apple Silicon.
- The CLI must NOT use the CPU-only CustomVoice code path present in the
inspected Voicebox implementation.
Expected rough resource profile for planning only:
- model storage: approximately 3 GB class
- working memory: approximately 4-6 GB class
- target hardware: M4-class Apple Silicon should be practical
These numbers must be measured on the actual target machine during development.
Do not hardcode assumptions about performance into the product.
======================================================================
6. WHY PYTHON FOR V1
======================================================================
The synthesis engine should initially be implemented in Python rather than
native Swift.
Reason:
- MLX-Audio's Python implementation is currently the safer and more mature path
for Qwen3-TTS CustomVoice.
- A CLI boundary makes the implementation language an internal detail.
- Other Swift, Flutter, Rust, Node, or Python applications can invoke Utter as a
subprocess.
- A native Swift/MLXAudioSwift implementation can be evaluated later without
changing the public CLI contract.
This is an architectural decision for MVP reliability, not a permanent
requirement.
======================================================================
7. CORE USER EXPERIENCE
======================================================================
Minimum happy path:
utter models pull
utter voices
utter speak "This is a flower." --voice Ryan -o flower.wav
Expected result:
- model is downloaded explicitly
- supported voices are shown
- selected voice is validated
- text is synthesized locally
- output file is a valid WAV
- command exits with code 0
- output file path is reported
======================================================================
8. CLI COMMANDS
======================================================================
The MVP should expose exactly these top-level areas:
utter speak
utter voices
utter models pull
utter models status
Optional but recommended:
utter --version
utter --help
utter speak --help
utter voices --help
utter models --help
======================================================================
9. COMMAND: utter voices
======================================================================
Purpose:
List available preset voices supported by the selected Qwen CustomVoice model.
Example:
utter voices
Human-readable output should include at minimum:
NAME
LANGUAGE/NOTES if known
Known Qwen CustomVoice preset speaker names from the inspected implementation:
- Vivian
- Serena
- Uncle_Fu
- Dylan
- Eric
- Ryan
- Aiden
- Ono_Anna
- Sohee
Ryan may be used as the default voice unless testing reveals a better default.
Also support:
utter voices --json
JSON output must be stable and machine-readable.
Example shape:
{
"voices": [
{
"id": "Ryan",
"name": "Ryan"
}
]
}
Do not silently invent aliases in MVP.
Voice IDs should map directly to Qwen speaker IDs.
======================================================================
10. COMMAND: utter speak
======================================================================
Primary syntax:
utter speak "This is a flower." --voice Ryan -o flower.wav
Also support:
utter speak "This is a flower." --voice Ryan --output flower.wav
Required arguments:
- text, unless --stdin is used
- output path, unless a documented default output behavior is implemented
Recommended options:
--voice <VOICE>
-o, --output <PATH>
--language <LANGUAGE>
--style <INSTRUCTION>
--stdin
--force
--json
Optional later:
--seed <INTEGER>
Do not add large numbers of generation parameters to the initial public API.
======================================================================
11. STDIN SUPPORT
======================================================================
Utter must support stdin because this makes it much easier to integrate with
other command-line tools and applications.
Example:
printf '%s' "This is a flower." | utter speak --stdin --voice Ryan -o flower.wav
Rules:
- --stdin means text must be read from stdin.
- Empty stdin is an error.
- Do not allow ambiguous simultaneous text argument + --stdin unless behavior is
explicitly documented. Prefer rejecting this combination.
- Preserve Unicode input correctly.
======================================================================
12. VOICE SELECTION
======================================================================
Voice selection should be intentionally simple.
User-facing value:
--voice Ryan
Internal model call should map directly to the Qwen CustomVoice speaker field.
Conceptually:
speaker = selected_voice
Then call the Qwen CustomVoice generation API with:
- text
- speaker
- language
- optional instruction/style
Do not create a database-backed voice-profile abstraction for MVP.
Instead use a static or model-derived typed catalog.
Validation requirements:
- exact valid voice IDs accepted
- invalid voice ID produces a clear error
- error should show or suggest available voices
- no silent fallback to another voice when the user explicitly chose an invalid
voice
======================================================================
13. STYLE / INSTRUCTION SUPPORT
======================================================================
Qwen CustomVoice supports instruction-based control.
Expose this as:
--style "Speak warmly and naturally."
Example:
utter speak "Welcome back." \
--voice Aiden \
--style "Speak calmly and warmly." \
-o welcome.wav
The CLI should pass this to the model's instruction field.
If no style is provided:
- do not invent one
- use the model's normal/default generation behavior
======================================================================
14. LANGUAGE SUPPORT
======================================================================
MVP should support an explicit language option:
--language en
or, if the underlying Qwen API expects full names:
--language English
Choose one canonical public representation and map internally.
Requirements:
- default should be English for MVP
- invalid language should produce a clear error
- language handling must not be guessed inconsistently
- keep language mapping in one module/configuration location
Do not attempt automatic language detection in MVP unless the underlying runtime
requires it and it is trivial and reliable.
======================================================================
15. AUDIO OUTPUT
======================================================================
Primary format for MVP:
WAV
Recommended output characteristics:
- 24 kHz
- mono
- PCM-16
The model may return floating-point waveform samples internally.
Pipeline:
model output
->
validate waveform
->
convert if necessary
->
write temporary WAV
->
atomically rename to final output path
The output file must be usable by normal macOS/iOS audio tooling.
======================================================================
16. ATOMIC FILE WRITING
======================================================================
Utter should use atomic output writing.
Example:
Requested destination:
/path/flower.wav
Temporary file:
/path/flower.wav.tmp
Process:
1. Generate complete waveform.
2. Validate waveform.
3. Write temporary WAV.
4. Flush/close file.
5. Confirm write succeeded.
6. Atomically rename temp file to final destination.
If generation or writing fails:
- remove temporary file when possible
- do not leave a partial final WAV
- return nonzero exit code
======================================================================
17. OUTPUT OVERWRITE BEHAVIOR
======================================================================
Default:
Do NOT overwrite an existing output file.
If destination exists:
error: output file already exists: flower.wav
use --force to overwrite
With:
--force
Utter may replace the destination atomically.
======================================================================
18. WAVEFORM VALIDATION
======================================================================
Before writing final audio, validate:
- waveform exists
- waveform is nonempty
- values are finite
- no NaN values
- no Inf values
- sample rate is valid
- output duration is greater than zero
If the waveform is invalid:
- do not write final output
- return nonzero exit code
- provide a concise error
======================================================================
19. MODEL MANAGEMENT
======================================================================
Model downloading must be explicit.
Do NOT silently download a multi-gigabyte model during:
utter speak
Instead:
utter models pull
should download/install the pinned model.
Then:
utter models status
should report whether the model is ready.
======================================================================
20. COMMAND: utter models pull
======================================================================
Responsibilities:
- resolve configured model repository
- resolve pinned model revision
- create deterministic cache directory
- download required model snapshot
- verify snapshot completion
- report success
- record model/runtime metadata
Example:
utter models pull
Suggested output:
Model: Qwen3-TTS 1.7B CustomVoice 8-bit
Status: downloading
...
Status: ready
Location: ~/Library/Caches/utter/models/...
Exact UI can differ, but behavior must be predictable.
======================================================================
21. COMMAND: utter models status
======================================================================
Example:
utter models status
Should report at minimum:
- model name
- model repository
- model revision
- quantization
- cache location
- installed/not installed
- complete/incomplete
- approximate disk usage if easy to obtain
- runtime version if available
Also support machine-readable JSON if practical:
utter models status --json
======================================================================
22. MODEL CACHE
======================================================================
Use a deterministic Utter-owned cache directory.
Recommended macOS location:
~/Library/Caches/utter/
Possible structure:
~/Library/Caches/utter/
models/
metadata/
Do not scatter model state throughout arbitrary project folders.
If Hugging Face caching is used internally, configure or wrap it so Utter can
determine exactly where its model lives.
MVP should record:
- model repository
- exact revision/commit
- quantization
- MLX-Audio version
- MLX version
- installation status
======================================================================
23. MODEL PINNING
======================================================================
Reliability is more important than always using the newest upstream build.
Pin:
- Python major/minor compatibility
- mlx version
- mlx-audio version
- huggingface_hub version
- audio-writing dependency
- Qwen model repository
- exact model revision when possible
Do not depend on floating "latest" versions in a production lockfile.
Upgrade dependencies intentionally and re-run the audio test corpus.
======================================================================
24. OFFLINE REQUIREMENT
======================================================================
After:
utter models pull
normal synthesis should work with networking disabled.
During:
utter speak
use local model files only.
If the model is missing:
Do NOT begin an implicit download.
Return an error such as:
model is not installed
run: utter models pull
======================================================================
25. PROCESS OUTPUT CONTRACT
======================================================================
Utter is intended to be called by other applications.
Therefore stdout/stderr discipline matters.
Recommended:
stdout:
- successful result information
- JSON output when --json is used
- final output path if human-readable mode
stderr:
- progress
- warnings
- diagnostics
- model loading progress
- errors
Exit codes:
0
success
Nonzero
failure
Use distinct codes where useful, but avoid overengineering.
Suggested categories:
1
generic runtime failure
2
CLI/argument validation failure
3
model missing/not ready
4
invalid voice/language
5
synthesis failure
6
output/write failure
These exact values may be adjusted, but they must be documented and stable once
released.
======================================================================
26. JSON MODE
======================================================================
Commands used by other applications should support stable JSON output where
useful.
Example:
utter speak "This is a flower." --voice Ryan -o flower.wav --json
Possible response:
{
"success": true,
"output": "/absolute/path/flower.wav",
"voice": "Ryan",
"model": "Qwen3-TTS-1.7B-CustomVoice-8bit",
"sample_rate": 24000,
"duration_seconds": 1.24
}
On failure:
{
"success": false,
"error": {
"code": "INVALID_VOICE",
"message": "Unknown voice: Bob"
}
}
When --json is active:
- stdout must contain valid JSON only
- diagnostic logs must go to stderr
======================================================================
27. INITIAL PROJECT STRUCTURE
======================================================================
Suggested structure:
utter/
pyproject.toml
README.md
LICENSE
spec.txt
src/
utter/
__init__.py
__main__.py
cli.py
config.py
constants.py
errors.py
commands/
__init__.py
speak.py
voices.py
models.py
tts/
__init__.py
engine.py
qwen_mlx.py
voices.py
models/
__init__.py
manifest.py
cache.py
downloader.py
audio/
__init__.py
validation.py
wav.py
output/
__init__.py
json_output.py
console.py
tests/
test_cli.py
test_voices.py
test_model_status.py
test_audio_validation.py
test_output_paths.py
test_json_output.py
scripts/
benchmark_m4.py
smoke_test.py
This structure is guidance, not a rigid requirement.
Prefer simple code over excessive abstraction.
======================================================================
28. TTS ENGINE ABSTRACTION
======================================================================
Do not overbuild a multi-provider architecture in MVP.
However, isolate Qwen runtime code behind a small internal interface so the
model implementation can later be replaced.
Conceptual interface:
class TTSEngine:
list_voices()
synthesize(text, voice, language, style) -> AudioResult
AudioResult should contain:
- waveform
- sample_rate
- metadata
Do not design a large plugin framework.
One clean interface is enough.
======================================================================
29. QWEN MLX ADAPTER
======================================================================
Create a dedicated module for Qwen CustomVoice through MLX-Audio.
Responsibilities:
- load the pinned MLX model
- cache the loaded model within the current process
- expose supported voices
- validate generation options
- invoke CustomVoice generation
- return waveform + sample rate
- translate runtime exceptions into Utter errors
Do NOT copy Voicebox's current PyTorch QwenCustomVoice backend.
Do NOT route CustomVoice through CPU on Apple Silicon.
Do NOT use the cloning-oriented Qwen Base path for preset voice synthesis.
======================================================================
30. MODEL LIFECYCLE
======================================================================
For a one-shot CLI process:
1. Parse command.
2. Validate model availability.
3. Load model.
4. Generate audio.
5. Save file.
6. Exit.
Loading may be the largest source of latency.
Do not build a daemon yet.
Measure cold-start performance first.
A future "utter serve" process may keep the model resident if repeated calls
from applications make cold-start overhead unacceptable.
======================================================================
31. FUTURE WARM SERVER MODE
======================================================================
NOT part of MVP.
Potential later command:
utter serve
Purpose:
- load Qwen model once
- keep it warm
- accept local requests
- reduce repeated model startup cost
Potential IPC:
- Unix domain socket
- localhost HTTP
- simple subprocess protocol
Preference for later investigation:
Unix domain socket or similarly local-only IPC
Do not implement until one-shot CLI benchmarks prove it is necessary.
======================================================================
32. LONG TEXT
======================================================================
MVP success criterion is short-to-medium text.
Do not build sophisticated long-document synthesis before the core command is
reliable.
After MVP, long text may use:
1. sentence-aware segmentation
2. sequential generation
3. small pause/crossfade joining
4. final WAV assembly
Voicebox uses chunking plus approximately small crossfades. That concept is
worth adapting later.
Requirements when implemented:
- never split in the middle of UTF-8 characters
- avoid splitting common abbreviations incorrectly where practical
- preserve punctuation
- test audible joins
- avoid clipping at boundaries
- make chunking deterministic
======================================================================
33. TRUE STREAMING
======================================================================
Not required for MVP.
The product's first job is to generate a correct audio file.
Do not call a feature "streaming" if the entire waveform is generated first and
only then emitted in blocks.
If genuine streaming is added later, document separately:
- time to first audio
- chunk format
- buffering strategy
- cancellation behavior
- final file assembly
======================================================================
34. ERROR HANDLING
======================================================================
Errors must be actionable.
Examples:
Missing model:
Error: Qwen3-TTS model is not installed.
Run: utter models pull
Invalid voice:
Error: unknown voice "Bob".