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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
// This file is @generated by prost-build.
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct StreamingSynthesisRequest {
#[prost(oneof = "streaming_synthesis_request::Payload", tags = "1, 2")]
pub payload: ::core::option::Option<streaming_synthesis_request::Payload>,
}
/// Nested message and enum types in `StreamingSynthesisRequest`.
pub mod streaming_synthesis_request {
#[derive(Clone, PartialEq, ::prost::Oneof)]
pub enum Payload {
/// FIRST message only: all synthesis parameters. Its `text` field may carry
/// the first complete sentence or be left empty.
#[prost(message, tag = "1")]
Header(super::SynthesisRequest),
/// Subsequent messages: one complete sentence to append to the live
/// synthesis.
#[prost(string, tag = "2")]
TextChunk(::prost::alloc::string::String),
}
}
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct SynthesisRequest {
/// BCP-47 language tag, e.g. "en".
/// Used to route the frontend pipeline and set backend language.
#[prost(string, optional, tag = "2")]
pub language: ::core::option::Option<::prost::alloc::string::String>,
/// Speaker name, e.g. "luna".
#[prost(string, optional, tag = "3")]
pub speaker: ::core::option::Option<::prost::alloc::string::String>,
/// Text to synthesize.
#[prost(string, tag = "4")]
pub text: ::prost::alloc::string::String,
#[prost(message, optional, tag = "5")]
pub audio_parameters: ::core::option::Option<AudioParameters>,
/// Controls how input text is split before synthesis.
/// Defaults to SPLIT_STRATEGY_SENTENCE when unset.
#[prost(enumeration = "SplitStrategy", optional, tag = "6")]
pub split_strategy: ::core::option::Option<i32>,
#[prost(message, optional, tag = "8")]
pub coda_parameters: ::core::option::Option<CodaParameters>,
#[prost(message, optional, tag = "9")]
pub mist_parameters: ::core::option::Option<MistParameters>,
/// Timestamps of the spoken spans of the synthesized audio, delivered in
/// the trailer once the audio has drained. Off unless requested.
#[prost(message, optional, tag = "10")]
pub timestamps: ::core::option::Option<TimestampOptions>,
/// Per-request pronunciation overrides. Validated against the request
/// language's phonology (an ill-formed entry fails the request) and applied by
/// the segmenter and the pronunciation stages. See
/// engine/src/pipeline/pronunciation.rs.
#[prost(message, repeated, tag = "11")]
pub custom_lexicon: ::prost::alloc::vec::Vec<PronunciationEntry>,
}
/// One custom-lexicon pronunciation override. The neural backend speaks
/// `spelling` (matched case-insensitively as a whole word) using `pronunciation`
/// wherever it occurs in the request text.
#[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
pub struct PronunciationEntry {
/// The word to override, e.g. "cache".
#[prost(string, tag = "1")]
pub spelling: ::prost::alloc::string::String,
/// Its X-SAMPA pronunciation, e.g. `" k { S` (primary stress, then phones).
#[prost(string, tag = "2")]
pub pronunciation: ::prost::alloc::string::String,
}
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct SynthesisResponseStream {
#[prost(oneof = "synthesis_response_stream::Payload", tags = "1, 2")]
pub payload: ::core::option::Option<synthesis_response_stream::Payload>,
}
/// Nested message and enum types in `SynthesisResponseStream`.
pub mod synthesis_response_stream {
#[derive(Clone, PartialEq, ::prost::Oneof)]
pub enum Payload {
/// A chunk of encoded audio, in the format requested.
#[prost(bytes, tag = "1")]
Audio(::prost::alloc::vec::Vec<u8>),
/// Sent once, after the last audio chunk, when the request asked for
/// anything it carries. A request that asked for nothing sees no trailer.
#[prost(message, tag = "2")]
Trailer(super::SynthesisResponseTrailer),
}
}
/// Results that settle only once the audio has drained.
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct SynthesisResponseTrailer {
/// Present when `timestamps.enable` was set.
#[prost(message, optional, tag = "1")]
pub timestamps: ::core::option::Option<Timestamps>,
}
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct AudioParameters {
/// Equivalent to the HTTP `Accept` header.
/// Examples: "audio/wav", "audio/mpeg", "audio/ogg;codecs=opus", "audio/l16".
#[prost(string, optional, tag = "1")]
pub audio_format: ::core::option::Option<::prost::alloc::string::String>,
#[prost(int32, optional, tag = "2")]
pub sampling_rate: ::core::option::Option<i32>,
#[prost(float, optional, tag = "3")]
pub time_scale_factor: ::core::option::Option<f32>,
}
#[derive(Clone, Copy, PartialEq, Eq, Hash, ::prost::Message)]
pub struct CodaParameters {
/// Streaming text input (`SynthesizeStreaming` / WebSocket `text`) only:
/// number of leading text tokens prefilled as a lookahead block so the first
/// audio frames have content context. Higher values improve content
/// robustness at the start of the utterance but delay the first audio until
/// that many text tokens have arrived. Clamped to the tokens available when
/// generation starts. Defaults to 0, which reproduces upstream Qwen3-TTS's
/// exact streaming layout. Ignored for one-shot synthesis (which always sees
/// the complete text up front).
#[prost(int32, optional, tag = "8")]
pub text_lookahead_tokens: ::core::option::Option<i32>,
}
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct MistParameters {
#[prost(bool, optional, tag = "1")]
pub pause_between_brackets: ::core::option::Option<bool>,
#[prost(bool, optional, tag = "2")]
pub phonemize_between_brackets: ::core::option::Option<bool>,
#[prost(float, repeated, tag = "3")]
pub inline_time_scale_factors: ::prost::alloc::vec::Vec<f32>,
#[prost(bool, optional, tag = "4")]
pub save_oovs: ::core::option::Option<bool>,
}
#[derive(Clone, Copy, PartialEq, Eq, Hash, ::prost::Message)]
pub struct TimestampOptions {
/// Report a SpanTimestamp for every spoken span. Costs one aligner
/// inference per request; never delays or fails the audio.
#[prost(bool, tag = "1")]
pub enable: bool,
}
/// One span of the text the talker spoke, as the aligner segments it: a
/// whitespace-separated word of the request text after normalization (so
/// numbers and abbreviations appear spelled out), or a morpheme for a
/// language written without spaces.
#[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
pub struct SpanTimestamp {
#[prost(string, tag = "1")]
pub text: ::prost::alloc::string::String,
/// Offsets from the start of the synthesized audio, at the audio's native
/// rate and before `time_scale_factor`.
#[prost(message, optional, tag = "2")]
pub start: ::core::option::Option<::pbjson_types::Duration>,
#[prost(message, optional, tag = "3")]
pub end: ::core::option::Option<::pbjson_types::Duration>,
}
/// The timestamps of one synthesis, delivered once after all audio: on gRPC
/// as `trailer.timestamps`, on WebSocket as `done.timestamps`. Absent when
/// the request did not ask for them. A non-OK status never fails the
/// synthesis that produced the audio.
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct Timestamps {
/// How the alignment settled, with `code` a google.rpc.Code. `OK` carries
/// spans; every other code carries none, with the reason in `message`:
/// INVALID_ARGUMENT the aligner does not support the request's
/// language, or rejected the utterance;
/// RESOURCE_EXHAUSTED the utterance exceeds what the aligner accepts,
/// or the branch lost input under load;
/// DEADLINE_EXCEEDED the aligner did not answer within its budget;
/// UNAVAILABLE the aligner worker is not serving;
/// UNIMPLEMENTED this package has no aligner;
/// CANCELLED synthesis ended before alignment settled.
#[prost(message, optional, tag = "1")]
pub status: ::core::option::Option<super::google::rpc::Status>,
#[prost(message, repeated, tag = "2")]
pub spans: ::prost::alloc::vec::Vec<SpanTimestamp>,
}
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct NormalizeTextRequest {
/// Text to normalize.
#[prost(string, tag = "1")]
pub text: ::prost::alloc::string::String,
/// BCP-47 language tag, e.g. "en".
#[prost(string, optional, tag = "2")]
pub language: ::core::option::Option<::prost::alloc::string::String>,
/// Per-request pronunciation overrides; same shape and validation as on
/// SynthesisRequest.
#[prost(message, repeated, tag = "3")]
pub custom_lexicon: ::prost::alloc::vec::Vec<PronunciationEntry>,
}
#[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
pub struct NormalizeTextResponse {
/// Deprecated: use normalized_sentences. Sentences are concatenated with no
/// whitespace separator, so multi-sentence inputs come back glued together.
#[prost(string, tag = "1")]
pub normalized_text: ::prost::alloc::string::String,
/// The normalized text, one entry per sentence emitted by the frontend
/// pipeline. Each entry is already trimmed; join with a single space to
/// reconstruct display text.
#[prost(string, repeated, tag = "2")]
pub normalized_sentences: ::prost::alloc::vec::Vec<::prost::alloc::string::String>,
}
/// Empty for now, but used instead of google.protobuf.Empty for extensibility.
#[derive(Clone, Copy, PartialEq, Eq, Hash, ::prost::Message)]
pub struct GetSupportedLanguagesRequest {}
#[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
pub struct GetSupportedLanguagesResponse {
/// List of supported BCP-47 language tags.
#[prost(string, repeated, tag = "1")]
pub languages: ::prost::alloc::vec::Vec<::prost::alloc::string::String>,
}
#[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
pub struct GetSupportedSpeakersRequest {
#[prost(string, optional, tag = "1")]
pub language: ::core::option::Option<::prost::alloc::string::String>,
}
#[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
pub struct GetSupportedSpeakersResponse {
/// List of supported speaker names for the given language.
#[prost(string, repeated, tag = "1")]
pub speakers: ::prost::alloc::vec::Vec<::prost::alloc::string::String>,
}
/// Client -> server. Exactly one message per WebSocket frame.
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct WebSocketRequest {
/// Client-chosen context identifier, at most 128 bytes. Empty selects the
/// context named "default". An identifier may be reused after its context
/// reaches a terminal event.
#[prost(string, tag = "1")]
pub context_id: ::prost::alloc::string::String,
#[prost(oneof = "web_socket_request::Payload", tags = "2, 3, 4, 5, 6")]
pub payload: ::core::option::Option<web_socket_request::Payload>,
}
/// Nested message and enum types in `WebSocketRequest`.
pub mod web_socket_request {
#[derive(Clone, PartialEq, ::prost::Oneof)]
pub enum Payload {
/// Connection-level configuration. At most one, and only before the first
/// `start`. Not required in debug mode or when the upgrade request
/// carried an `Authorization` header.
#[prost(message, tag = "2")]
Config(super::WebSocketConfig),
/// Opens the context with the full synthesis parameters. A non-empty
/// `text` is the complete input for one-shot synthesis: audio streams
/// and ends with `done`, no `end` required. An empty `text` opens a
/// streaming context that stays open for `text` messages and finalizes
/// on `end`.
#[prost(message, tag = "3")]
Start(super::SynthesisRequest),
/// Appends a chunk of input text to an open streaming context (one opened
/// with an empty `start.text`). The engine meters, segments, and
/// synthesizes it into the same continuous audio as it arrives. Rejected
/// with kind "invalid_input" if the context is not open for input (no
/// `start`, or already `end`ed / one-shot).
#[prost(string, tag = "4")]
Text(::prost::alloc::string::String),
/// Declares end of input for a streaming context. Remaining audio is
/// delivered, followed by `done`. A no-op for a one-shot context. The
/// connection stays open for further contexts.
#[prost(message, tag = "5")]
End(super::WebSocketEnd),
/// Aborts the context immediately, discarding in-flight synthesis.
/// Acknowledged with `cancelled`; idempotent (cancelling an unknown or
/// finished context is not an error).
#[prost(message, tag = "6")]
Cancel(super::WebSocketCancel),
}
}
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct WebSocketConfig {
/// Mirrors the HTTP `Authorization` header, e.g. "Api-Key <key>".
/// Rejected if the upgrade request already carried an Authorization header.
#[prost(string, optional, tag = "1")]
pub authorization: ::core::option::Option<::prost::alloc::string::String>,
/// License JSON for on-prem deployments; mirrors the `x-rime-license`
/// gRPC metadata / the `license` field of the HTTP API.
#[prost(string, optional, tag = "2")]
pub license: ::core::option::Option<::prost::alloc::string::String>,
/// Defaults merged (field-wise, shallow) under every subsequent `start`.
/// Its `text` field is ignored.
#[prost(message, optional, tag = "3")]
pub defaults: ::core::option::Option<SynthesisRequest>,
}
#[derive(Clone, Copy, PartialEq, Eq, Hash, ::prost::Message)]
pub struct WebSocketEnd {}
#[derive(Clone, Copy, PartialEq, Eq, Hash, ::prost::Message)]
pub struct WebSocketCancel {}
/// Server -> client. Exactly one message per WebSocket frame.
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct WebSocketResponse {
/// Context the payload applies to. Empty for connection-scoped payloads
/// (`ready` and connection-level `error`s).
#[prost(string, tag = "1")]
pub context_id: ::prost::alloc::string::String,
#[prost(oneof = "web_socket_response::Payload", tags = "2, 3, 4, 5, 6, 7")]
pub payload: ::core::option::Option<web_socket_response::Payload>,
}
/// Nested message and enum types in `WebSocketResponse`.
pub mod web_socket_response {
#[derive(Clone, PartialEq, ::prost::Oneof)]
pub enum Payload {
/// Sent once per connection when the engine is ready to synthesize
/// (pipelines loaded and serving). Gate `start` on this event.
#[prost(message, tag = "2")]
Ready(super::WebSocketReady),
/// The context was accepted; precedes any of its audio.
#[prost(message, tag = "3")]
Started(super::WebSocketStarted),
/// A chunk of encoded audio, in the format requested at `start`.
#[prost(bytes, tag = "4")]
Audio(::prost::alloc::vec::Vec<u8>),
/// Terminal: all audio for the context has been delivered.
#[prost(message, tag = "5")]
Done(super::WebSocketDone),
/// Terminal: the context was aborted by `cancel`.
#[prost(message, tag = "6")]
Cancelled(super::WebSocketCancelled),
/// Terminal for the context it names. Errors with an empty `context_id`
/// are connection-scoped and leave open contexts running; the server
/// closes the connection only when the failure is unrecoverable
/// (undecodable frames, failed authentication).
#[prost(message, tag = "7")]
Error(super::WebSocketError),
}
}
#[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
pub struct WebSocketReady {
/// Protocol version. Currently 1.
#[prost(uint32, tag = "1")]
pub protocol: u32,
/// Supported BCP-47 language tags (mirrors GetSupportedLanguages).
#[prost(string, repeated, tag = "2")]
pub languages: ::prost::alloc::vec::Vec<::prost::alloc::string::String>,
#[prost(string, optional, tag = "3")]
pub default_language: ::core::option::Option<::prost::alloc::string::String>,
}
#[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
pub struct WebSocketStarted {
/// Engine request id for this context; correlates with engine logs and
/// matches the `x-request-id` gRPC/HTTP metadata.
#[prost(string, tag = "1")]
pub request_id: ::prost::alloc::string::String,
}
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct WebSocketDone {
/// Present when `start.timestamps.enable` was set.
#[prost(message, optional, tag = "1")]
pub timestamps: ::core::option::Option<Timestamps>,
}
#[derive(Clone, Copy, PartialEq, Eq, Hash, ::prost::Message)]
pub struct WebSocketCancelled {}
#[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
pub struct WebSocketError {
/// Stable machine-readable kind; same values as the HTTP error body
/// (e.g. "invalid_input", "unauthenticated", "unavailable", "internal",
/// "unimplemented").
#[prost(string, tag = "1")]
pub kind: ::prost::alloc::string::String,
/// Human-readable description.
#[prost(string, tag = "2")]
pub message: ::prost::alloc::string::String,
/// Engine request id, when the error occurred inside a synthesis request.
#[prost(string, optional, tag = "3")]
pub request_id: ::core::option::Option<::prost::alloc::string::String>,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, ::prost::Enumeration)]
#[repr(i32)]
pub enum SplitStrategy {
Unspecified = 0,
Sentence = 1,
None = 2,
/// Accumulates streamed sub-sentential text tokens into complete sentences
/// before synthesis. Only valid for streaming requests
/// (SynthesizeStreaming or the WebSocket API); a unary Synthesize request
/// that asks for it is rejected.
AccumulateSentence = 3,
}
impl SplitStrategy {
/// String value of the enum field names used in the ProtoBuf definition.
///
/// The values are not transformed in any way and thus are considered stable
/// (if the ProtoBuf definition does not change) and safe for programmatic use.
pub fn as_str_name(&self) -> &'static str {
match self {
Self::Unspecified => "SPLIT_STRATEGY_UNSPECIFIED",
Self::Sentence => "SPLIT_STRATEGY_SENTENCE",
Self::None => "SPLIT_STRATEGY_NONE",
Self::AccumulateSentence => "SPLIT_STRATEGY_ACCUMULATE_SENTENCE",
}
}
/// Creates an enum from field names used in the ProtoBuf definition.
pub fn from_str_name(value: &str) -> ::core::option::Option<Self> {
match value {
"SPLIT_STRATEGY_UNSPECIFIED" => Some(Self::Unspecified),
"SPLIT_STRATEGY_SENTENCE" => Some(Self::Sentence),
"SPLIT_STRATEGY_NONE" => Some(Self::None),
"SPLIT_STRATEGY_ACCUMULATE_SENTENCE" => Some(Self::AccumulateSentence),
_ => None,
}
}
}
/// Generated client implementations.
#[cfg(feature = "grpc")]
pub mod text_to_speech_client {
#![allow(
unused_variables,
dead_code,
missing_docs,
clippy::wildcard_imports,
clippy::let_unit_value,
)]
use tonic::codegen::*;
use tonic::codegen::http::Uri;
#[derive(Debug, Clone)]
pub struct TextToSpeechClient<T> {
inner: tonic::client::Grpc<T>,
}
impl TextToSpeechClient<tonic::transport::Channel> {
/// Attempt to create a new client by connecting to a given endpoint.
pub async fn connect<D>(dst: D) -> Result<Self, tonic::transport::Error>
where
D: TryInto<tonic::transport::Endpoint>,
D::Error: Into<StdError>,
{
let conn = tonic::transport::Endpoint::new(dst)?.connect().await?;
Ok(Self::new(conn))
}
}
impl<T> TextToSpeechClient<T>
where
T: tonic::client::GrpcService<tonic::body::Body>,
T::Error: Into<StdError>,
T::ResponseBody: Body<Data = Bytes> + std::marker::Send + 'static,
<T::ResponseBody as Body>::Error: Into<StdError> + std::marker::Send,
{
pub fn new(inner: T) -> Self {
let inner = tonic::client::Grpc::new(inner);
Self { inner }
}
pub fn with_origin(inner: T, origin: Uri) -> Self {
let inner = tonic::client::Grpc::with_origin(inner, origin);
Self { inner }
}
pub fn with_interceptor<F>(
inner: T,
interceptor: F,
) -> TextToSpeechClient<InterceptedService<T, F>>
where
F: tonic::service::Interceptor,
T::ResponseBody: Default,
T: tonic::codegen::Service<
http::Request<tonic::body::Body>,
Response = http::Response<
<T as tonic::client::GrpcService<tonic::body::Body>>::ResponseBody,
>,
>,
<T as tonic::codegen::Service<
http::Request<tonic::body::Body>,
>>::Error: Into<StdError> + std::marker::Send + std::marker::Sync,
{
TextToSpeechClient::new(InterceptedService::new(inner, interceptor))
}
/// Compress requests with the given encoding.
///
/// This requires the server to support it otherwise it might respond with an
/// error.
#[must_use]
pub fn send_compressed(mut self, encoding: CompressionEncoding) -> Self {
self.inner = self.inner.send_compressed(encoding);
self
}
/// Enable decompressing responses.
#[must_use]
pub fn accept_compressed(mut self, encoding: CompressionEncoding) -> Self {
self.inner = self.inner.accept_compressed(encoding);
self
}
/// Limits the maximum size of a decoded message.
///
/// Default: `4MB`
#[must_use]
pub fn max_decoding_message_size(mut self, limit: usize) -> Self {
self.inner = self.inner.max_decoding_message_size(limit);
self
}
/// Limits the maximum size of an encoded message.
///
/// Default: `usize::MAX`
#[must_use]
pub fn max_encoding_message_size(mut self, limit: usize) -> Self {
self.inner = self.inner.max_encoding_message_size(limit);
self
}
pub async fn synthesize(
&mut self,
request: impl tonic::IntoRequest<super::SynthesisRequest>,
) -> std::result::Result<
tonic::Response<tonic::codec::Streaming<super::SynthesisResponseStream>>,
tonic::Status,
> {
self.inner
.ready()
.await
.map_err(|e| {
tonic::Status::unknown(
format!("Service was not ready: {}", e.into()),
)
})?;
let codec = tonic_prost::ProstCodec::default();
let path = http::uri::PathAndQuery::from_static(
"/rime.TextToSpeech/Synthesize",
);
let mut req = request.into_request();
req.extensions_mut()
.insert(GrpcMethod::new("rime.TextToSpeech", "Synthesize"));
self.inner.server_streaming(req, path, codec).await
}
/// Streaming text input: the client feeds text incrementally into a single
/// continuous synthesis. The FIRST client message MUST set `header` (all
/// synthesis params; its `text` field may carry the first chunk or be empty);
/// subsequent messages set `text_chunk`. End-of-input is signalled by the
/// client half-closing the request stream. Audio frames stream back as they
/// are produced.
pub async fn synthesize_streaming(
&mut self,
request: impl tonic::IntoStreamingRequest<
Message = super::StreamingSynthesisRequest,
>,
) -> std::result::Result<
tonic::Response<tonic::codec::Streaming<super::SynthesisResponseStream>>,
tonic::Status,
> {
self.inner
.ready()
.await
.map_err(|e| {
tonic::Status::unknown(
format!("Service was not ready: {}", e.into()),
)
})?;
let codec = tonic_prost::ProstCodec::default();
let path = http::uri::PathAndQuery::from_static(
"/rime.TextToSpeech/SynthesizeStreaming",
);
let mut req = request.into_streaming_request();
req.extensions_mut()
.insert(GrpcMethod::new("rime.TextToSpeech", "SynthesizeStreaming"));
self.inner.streaming(req, path, codec).await
}
pub async fn normalize_text(
&mut self,
request: impl tonic::IntoRequest<super::NormalizeTextRequest>,
) -> std::result::Result<
tonic::Response<super::NormalizeTextResponse>,
tonic::Status,
> {
self.inner
.ready()
.await
.map_err(|e| {
tonic::Status::unknown(
format!("Service was not ready: {}", e.into()),
)
})?;
let codec = tonic_prost::ProstCodec::default();
let path = http::uri::PathAndQuery::from_static(
"/rime.TextToSpeech/NormalizeText",
);
let mut req = request.into_request();
req.extensions_mut()
.insert(GrpcMethod::new("rime.TextToSpeech", "NormalizeText"));
self.inner.unary(req, path, codec).await
}
pub async fn get_supported_languages(
&mut self,
request: impl tonic::IntoRequest<super::GetSupportedLanguagesRequest>,
) -> std::result::Result<
tonic::Response<super::GetSupportedLanguagesResponse>,
tonic::Status,
> {
self.inner
.ready()
.await
.map_err(|e| {
tonic::Status::unknown(
format!("Service was not ready: {}", e.into()),
)
})?;
let codec = tonic_prost::ProstCodec::default();
let path = http::uri::PathAndQuery::from_static(
"/rime.TextToSpeech/GetSupportedLanguages",
);
let mut req = request.into_request();
req.extensions_mut()
.insert(GrpcMethod::new("rime.TextToSpeech", "GetSupportedLanguages"));
self.inner.unary(req, path, codec).await
}
pub async fn get_supported_speakers(
&mut self,
request: impl tonic::IntoRequest<super::GetSupportedSpeakersRequest>,
) -> std::result::Result<
tonic::Response<super::GetSupportedSpeakersResponse>,
tonic::Status,
> {
self.inner
.ready()
.await
.map_err(|e| {
tonic::Status::unknown(
format!("Service was not ready: {}", e.into()),
)
})?;
let codec = tonic_prost::ProstCodec::default();
let path = http::uri::PathAndQuery::from_static(
"/rime.TextToSpeech/GetSupportedSpeakers",
);
let mut req = request.into_request();
req.extensions_mut()
.insert(GrpcMethod::new("rime.TextToSpeech", "GetSupportedSpeakers"));
self.inner.unary(req, path, codec).await
}
}
}
/// Generated server implementations.
#[cfg(feature = "grpc")]
pub mod text_to_speech_server {
#![allow(
unused_variables,
dead_code,
missing_docs,
clippy::wildcard_imports,
clippy::let_unit_value,
)]
use tonic::codegen::*;
/// Generated trait containing gRPC methods that should be implemented for use with TextToSpeechServer.
#[async_trait]
pub trait TextToSpeech: std::marker::Send + std::marker::Sync + 'static {
/// Server streaming response type for the Synthesize method.
type SynthesizeStream: tonic::codegen::tokio_stream::Stream<
Item = std::result::Result<super::SynthesisResponseStream, tonic::Status>,
>
+ std::marker::Send
+ 'static;
async fn synthesize(
&self,
request: tonic::Request<super::SynthesisRequest>,
) -> std::result::Result<tonic::Response<Self::SynthesizeStream>, tonic::Status>;
/// Server streaming response type for the SynthesizeStreaming method.
type SynthesizeStreamingStream: tonic::codegen::tokio_stream::Stream<
Item = std::result::Result<super::SynthesisResponseStream, tonic::Status>,
>
+ std::marker::Send
+ 'static;
/// Streaming text input: the client feeds text incrementally into a single
/// continuous synthesis. The FIRST client message MUST set `header` (all
/// synthesis params; its `text` field may carry the first chunk or be empty);
/// subsequent messages set `text_chunk`. End-of-input is signalled by the
/// client half-closing the request stream. Audio frames stream back as they
/// are produced.
async fn synthesize_streaming(
&self,
request: tonic::Request<tonic::Streaming<super::StreamingSynthesisRequest>>,
) -> std::result::Result<
tonic::Response<Self::SynthesizeStreamingStream>,
tonic::Status,
>;
async fn normalize_text(
&self,
request: tonic::Request<super::NormalizeTextRequest>,
) -> std::result::Result<
tonic::Response<super::NormalizeTextResponse>,
tonic::Status,
>;
async fn get_supported_languages(
&self,
request: tonic::Request<super::GetSupportedLanguagesRequest>,
) -> std::result::Result<
tonic::Response<super::GetSupportedLanguagesResponse>,
tonic::Status,
>;
async fn get_supported_speakers(
&self,
request: tonic::Request<super::GetSupportedSpeakersRequest>,
) -> std::result::Result<
tonic::Response<super::GetSupportedSpeakersResponse>,
tonic::Status,
>;
}
#[derive(Debug)]
pub struct TextToSpeechServer<T> {
inner: Arc<T>,
accept_compression_encodings: EnabledCompressionEncodings,
send_compression_encodings: EnabledCompressionEncodings,
max_decoding_message_size: Option<usize>,
max_encoding_message_size: Option<usize>,
}
impl<T> TextToSpeechServer<T> {
pub fn new(inner: T) -> Self {
Self::from_arc(Arc::new(inner))
}
pub fn from_arc(inner: Arc<T>) -> Self {
Self {
inner,
accept_compression_encodings: Default::default(),
send_compression_encodings: Default::default(),
max_decoding_message_size: None,
max_encoding_message_size: None,
}
}
pub fn with_interceptor<F>(
inner: T,
interceptor: F,
) -> InterceptedService<Self, F>
where
F: tonic::service::Interceptor,
{
InterceptedService::new(Self::new(inner), interceptor)
}
/// Enable decompressing requests with the given encoding.
#[must_use]
pub fn accept_compressed(mut self, encoding: CompressionEncoding) -> Self {
self.accept_compression_encodings.enable(encoding);
self
}
/// Compress responses with the given encoding, if the client supports it.
#[must_use]
pub fn send_compressed(mut self, encoding: CompressionEncoding) -> Self {
self.send_compression_encodings.enable(encoding);
self
}
/// Limits the maximum size of a decoded message.
///
/// Default: `4MB`
#[must_use]
pub fn max_decoding_message_size(mut self, limit: usize) -> Self {
self.max_decoding_message_size = Some(limit);
self
}
/// Limits the maximum size of an encoded message.
///
/// Default: `usize::MAX`
#[must_use]
pub fn max_encoding_message_size(mut self, limit: usize) -> Self {
self.max_encoding_message_size = Some(limit);
self
}
}
impl<T, B> tonic::codegen::Service<http::Request<B>> for TextToSpeechServer<T>
where
T: TextToSpeech,
B: Body + std::marker::Send + 'static,
B::Error: Into<StdError> + std::marker::Send + 'static,
{
type Response = http::Response<tonic::body::Body>;
type Error = std::convert::Infallible;
type Future = BoxFuture<Self::Response, Self::Error>;
fn poll_ready(
&mut self,
_cx: &mut Context<'_>,
) -> Poll<std::result::Result<(), Self::Error>> {
Poll::Ready(Ok(()))
}
fn call(&mut self, req: http::Request<B>) -> Self::Future {
match req.uri().path() {
"/rime.TextToSpeech/Synthesize" => {
#[allow(non_camel_case_types)]
struct SynthesizeSvc<T: TextToSpeech>(pub Arc<T>);
impl<
T: TextToSpeech,
> tonic::server::ServerStreamingService<super::SynthesisRequest>
for SynthesizeSvc<T> {
type Response = super::SynthesisResponseStream;
type ResponseStream = T::SynthesizeStream;
type Future = BoxFuture<
tonic::Response<Self::ResponseStream>,
tonic::Status,
>;
fn call(
&mut self,
request: tonic::Request<super::SynthesisRequest>,
) -> Self::Future {
let inner = Arc::clone(&self.0);
let fut = async move {
<T as TextToSpeech>::synthesize(&inner, request).await
};
Box::pin(fut)
}
}
let accept_compression_encodings = self.accept_compression_encodings;
let send_compression_encodings = self.send_compression_encodings;
let max_decoding_message_size = self.max_decoding_message_size;
let max_encoding_message_size = self.max_encoding_message_size;
let inner = self.inner.clone();
let fut = async move {
let method = SynthesizeSvc(inner);
let codec = tonic_prost::ProstCodec::default();
let mut grpc = tonic::server::Grpc::new(codec)
.apply_compression_config(
accept_compression_encodings,
send_compression_encodings,
)
.apply_max_message_size_config(
max_decoding_message_size,
max_encoding_message_size,
);
let res = grpc.server_streaming(method, req).await;
Ok(res)
};
Box::pin(fut)
}
"/rime.TextToSpeech/SynthesizeStreaming" => {
#[allow(non_camel_case_types)]
struct SynthesizeStreamingSvc<T: TextToSpeech>(pub Arc<T>);
impl<
T: TextToSpeech,
> tonic::server::StreamingService<super::StreamingSynthesisRequest>
for SynthesizeStreamingSvc<T> {
type Response = super::SynthesisResponseStream;
type ResponseStream = T::SynthesizeStreamingStream;
type Future = BoxFuture<
tonic::Response<Self::ResponseStream>,
tonic::Status,
>;
fn call(
&mut self,
request: tonic::Request<
tonic::Streaming<super::StreamingSynthesisRequest>,
>,
) -> Self::Future {
let inner = Arc::clone(&self.0);
let fut = async move {
<T as TextToSpeech>::synthesize_streaming(&inner, request)
.await
};
Box::pin(fut)
}
}
let accept_compression_encodings = self.accept_compression_encodings;
let send_compression_encodings = self.send_compression_encodings;
let max_decoding_message_size = self.max_decoding_message_size;
let max_encoding_message_size = self.max_encoding_message_size;
let inner = self.inner.clone();
let fut = async move {
let method = SynthesizeStreamingSvc(inner);
let codec = tonic_prost::ProstCodec::default();
let mut grpc = tonic::server::Grpc::new(codec)
.apply_compression_config(
accept_compression_encodings,
send_compression_encodings,
)
.apply_max_message_size_config(
max_decoding_message_size,
max_encoding_message_size,
);
let res = grpc.streaming(method, req).await;
Ok(res)
};
Box::pin(fut)
}
"/rime.TextToSpeech/NormalizeText" => {
#[allow(non_camel_case_types)]
struct NormalizeTextSvc<T: TextToSpeech>(pub Arc<T>);
impl<
T: TextToSpeech,
> tonic::server::UnaryService<super::NormalizeTextRequest>
for NormalizeTextSvc<T> {
type Response = super::NormalizeTextResponse;
type Future = BoxFuture<
tonic::Response<Self::Response>,
tonic::Status,
>;
fn call(
&mut self,
request: tonic::Request<super::NormalizeTextRequest>,
) -> Self::Future {
let inner = Arc::clone(&self.0);
let fut = async move {
<T as TextToSpeech>::normalize_text(&inner, request).await
};
Box::pin(fut)
}
}
let accept_compression_encodings = self.accept_compression_encodings;
let send_compression_encodings = self.send_compression_encodings;
let max_decoding_message_size = self.max_decoding_message_size;
let max_encoding_message_size = self.max_encoding_message_size;
let inner = self.inner.clone();
let fut = async move {
let method = NormalizeTextSvc(inner);
let codec = tonic_prost::ProstCodec::default();
let mut grpc = tonic::server::Grpc::new(codec)
.apply_compression_config(
accept_compression_encodings,
send_compression_encodings,
)
.apply_max_message_size_config(
max_decoding_message_size,
max_encoding_message_size,
);
let res = grpc.unary(method, req).await;
Ok(res)
};
Box::pin(fut)
}
"/rime.TextToSpeech/GetSupportedLanguages" => {
#[allow(non_camel_case_types)]
struct GetSupportedLanguagesSvc<T: TextToSpeech>(pub Arc<T>);
impl<
T: TextToSpeech,
> tonic::server::UnaryService<super::GetSupportedLanguagesRequest>
for GetSupportedLanguagesSvc<T> {
type Response = super::GetSupportedLanguagesResponse;
type Future = BoxFuture<
tonic::Response<Self::Response>,
tonic::Status,
>;
fn call(
&mut self,
request: tonic::Request<super::GetSupportedLanguagesRequest>,
) -> Self::Future {
let inner = Arc::clone(&self.0);
let fut = async move {
<T as TextToSpeech>::get_supported_languages(
&inner,
request,
)
.await
};
Box::pin(fut)
}
}
let accept_compression_encodings = self.accept_compression_encodings;
let send_compression_encodings = self.send_compression_encodings;
let max_decoding_message_size = self.max_decoding_message_size;
let max_encoding_message_size = self.max_encoding_message_size;
let inner = self.inner.clone();
let fut = async move {
let method = GetSupportedLanguagesSvc(inner);
let codec = tonic_prost::ProstCodec::default();
let mut grpc = tonic::server::Grpc::new(codec)
.apply_compression_config(
accept_compression_encodings,
send_compression_encodings,
)
.apply_max_message_size_config(
max_decoding_message_size,
max_encoding_message_size,
);
let res = grpc.unary(method, req).await;
Ok(res)
};
Box::pin(fut)
}
"/rime.TextToSpeech/GetSupportedSpeakers" => {
#[allow(non_camel_case_types)]
struct GetSupportedSpeakersSvc<T: TextToSpeech>(pub Arc<T>);
impl<
T: TextToSpeech,
> tonic::server::UnaryService<super::GetSupportedSpeakersRequest>
for GetSupportedSpeakersSvc<T> {
type Response = super::GetSupportedSpeakersResponse;
type Future = BoxFuture<
tonic::Response<Self::Response>,
tonic::Status,
>;
fn call(
&mut self,
request: tonic::Request<super::GetSupportedSpeakersRequest>,
) -> Self::Future {
let inner = Arc::clone(&self.0);
let fut = async move {
<T as TextToSpeech>::get_supported_speakers(&inner, request)
.await
};
Box::pin(fut)
}
}
let accept_compression_encodings = self.accept_compression_encodings;
let send_compression_encodings = self.send_compression_encodings;
let max_decoding_message_size = self.max_decoding_message_size;
let max_encoding_message_size = self.max_encoding_message_size;
let inner = self.inner.clone();
let fut = async move {
let method = GetSupportedSpeakersSvc(inner);
let codec = tonic_prost::ProstCodec::default();
let mut grpc = tonic::server::Grpc::new(codec)
.apply_compression_config(
accept_compression_encodings,
send_compression_encodings,
)
.apply_max_message_size_config(
max_decoding_message_size,
max_encoding_message_size,
);
let res = grpc.unary(method, req).await;
Ok(res)
};
Box::pin(fut)
}
_ => {
Box::pin(async move {
let mut response = http::Response::new(
tonic::body::Body::default(),
);
let headers = response.headers_mut();
headers
.insert(
tonic::Status::GRPC_STATUS,
(tonic::Code::Unimplemented as i32).into(),
);
headers
.insert(
http::header::CONTENT_TYPE,
tonic::metadata::GRPC_CONTENT_TYPE,
);
Ok(response)
})
}
}
}
}
impl<T> Clone for TextToSpeechServer<T> {
fn clone(&self) -> Self {
let inner = self.inner.clone();
Self {
inner,
accept_compression_encodings: self.accept_compression_encodings,
send_compression_encodings: self.send_compression_encodings,
max_decoding_message_size: self.max_decoding_message_size,
max_encoding_message_size: self.max_encoding_message_size,
}
}
}
/// Generated gRPC service name
pub const SERVICE_NAME: &str = "rime.TextToSpeech";
impl<T> tonic::server::NamedService for TextToSpeechServer<T> {
const NAME: &'static str = SERVICE_NAME;
}
}
#[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
pub struct TranscriptionOptions {
/// Required BCP-47 tag of the spoken language, resolved against the packaged
/// catalog (`en` or `es`). An omitted tag or `und` is rejected with
/// INVALID_ARGUMENT.
#[prost(string, optional, tag = "1")]
pub language: ::core::option::Option<::prost::alloc::string::String>,
#[prost(enumeration = "TranscriptionMode", tag = "2")]
pub mode: i32,
/// Recognition terms, for example \["Mitchell Gourley", "Super-G", "USOC"\].
/// An empty list adds no bias; the service rejects empty or whitespace-only
/// terms. Order and term text are preserved, with ", " inserted between
/// terms before composition into the packaged mode prompt. The packaged
/// model's caller-context budget counts UTF-8 bytes including separators;
/// the composed prompt keeps the mode prompt intact.
/// Terms softly bias recognition without forcing a match; per-word weights
/// are not supported.
#[prost(string, repeated, tag = "3")]
pub context_terms: ::prost::alloc::vec::Vec<::prost::alloc::string::String>,
}
#[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
pub struct ResolvedLanguage {
/// Canonical BCP-47 tag drawn from the packaged model catalog.
#[prost(string, tag = "1")]
pub tag: ::prost::alloc::string::String,
#[prost(enumeration = "LanguageSource", tag = "2")]
pub source: i32,
}
#[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
pub struct TranscriptionRequest {
/// A complete WAV file, including its RIFF/WAVE header, bounded to 16 MiB.
/// PCM16 little-endian mono 16 kHz is the qualified input format. The
/// packaged decoder may accept other WAV encodings/rates; those extensions
/// are not a portable interface guarantee. Headerless PCM is not WAV.
#[prost(bytes = "vec", tag = "1")]
pub audio: ::prost::alloc::vec::Vec<u8>,
/// Required: `language` must select the spoken language.
#[prost(message, optional, tag = "2")]
pub options: ::core::option::Option<TranscriptionOptions>,
}
#[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
pub struct TranscriptionResponse {
#[prost(string, tag = "1")]
pub text: ::prost::alloc::string::String,
/// The canonical catalog language the caller selected.
#[prost(message, optional, tag = "2")]
pub language: ::core::option::Option<ResolvedLanguage>,
}
/// Streaming input is always headerless signed PCM16 little-endian mono
/// 16 kHz; the format is not configurable.
#[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
pub struct StreamingConfig {
/// Under either output contract, `language` is a required BCP-47 tag (an
/// omitted tag or `und` is rejected) and `mode` selects the written or
/// verbatim prompt.
#[prost(string, optional, tag = "3")]
pub language: ::core::option::Option<::prost::alloc::string::String>,
#[prost(enumeration = "TranscriptionMode", tag = "4")]
pub mode: i32,
/// Explicitly selects the output contract. The service confirms the
/// selection before accepting audio; an unrecognized value is rejected
/// rather than silently downgraded.
#[prost(enumeration = "StreamingOutputContract", tag = "5")]
pub output_contract: i32,
/// Recognition terms under either output contract. Same validation, budgets
/// and composition as TranscriptionOptions.context_terms; an empty list adds
/// no bias.
#[prost(string, repeated, tag = "6")]
pub context_terms: ::prost::alloc::vec::Vec<::prost::alloc::string::String>,
}
#[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
pub struct StreamingTranscriptionRequest {
#[prost(oneof = "streaming_transcription_request::Payload", tags = "1, 2")]
pub payload: ::core::option::Option<streaming_transcription_request::Payload>,
}
/// Nested message and enum types in `StreamingTranscriptionRequest`.
pub mod streaming_transcription_request {
#[derive(Clone, PartialEq, Eq, Hash, ::prost::Oneof)]
pub enum Payload {
/// Required exactly once as the first request.
#[prost(message, tag = "1")]
Config(super::StreamingConfig),
/// PCM16 bytes. Each message is bounded to 64 KiB and the utterance to
/// 16 MiB. An odd byte count is invalid.
#[prost(bytes, tag = "2")]
Audio(::prost::alloc::vec::Vec<u8>),
}
}
#[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
pub struct StreamingTranscriptionResponse {
#[prost(oneof = "streaming_transcription_response::Payload", tags = "1, 2, 3, 4")]
pub payload: ::core::option::Option<streaming_transcription_response::Payload>,
}
/// Nested message and enum types in `StreamingTranscriptionResponse`.
pub mod streaming_transcription_response {
#[derive(Clone, PartialEq, Eq, Hash, ::prost::Oneof)]
pub enum Payload {
/// An append-only transcript fragment under the append-fragment contract.
/// Concatenate deltas in arrival order, including newline separators
/// between transcription windows; they are not replacement hypotheses.
#[prost(message, tag = "1")]
Delta(super::TranscriptionDelta),
/// Exactly one final transcript for a successfully completed utterance.
/// Under the append-fragment contract its text equals the concatenation of
/// all preceding delta fragments; under
/// STREAMING_OUTPUT_CONTRACT_REVISED_HYPOTHESES it equals the last
/// hypothesis. It may be empty when the input contains no recognized
/// speech.
#[prost(message, tag = "2")]
Done(super::TranscriptionDone),
/// Confirms the selected output contract before any audio-derived
/// response. Every accepted configuration selects
/// STREAMING_OUTPUT_CONTRACT_APPEND_FRAGMENTS or
/// STREAMING_OUTPUT_CONTRACT_REVISED_HYPOTHESES;
/// STREAMING_OUTPUT_CONTRACT_UNSPECIFIED is rejected as invalid input.
#[prost(message, tag = "3")]
Accepted(super::StreamingAccepted),
/// The latest full transcript hypothesis under
/// STREAMING_OUTPUT_CONTRACT_REVISED_HYPOTHESES. Each hypothesis replaces
/// the previous one entirely.
#[prost(message, tag = "4")]
Hypothesis(super::TranscriptionHypothesis),
}
}
#[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
pub struct StreamingAccepted {
#[prost(enumeration = "StreamingOutputContract", tag = "1")]
pub output_contract: i32,
/// Confirms the selected language.
#[prost(message, optional, tag = "2")]
pub language: ::core::option::Option<ResolvedLanguage>,
}
#[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
pub struct TranscriptionDelta {
#[prost(string, tag = "1")]
pub text: ::prost::alloc::string::String,
}
/// A full-hypothesis partial. `text` is the complete current transcript, not a
/// delta; a later hypothesis with a higher revision replaces it.
#[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
pub struct TranscriptionHypothesis {
#[prost(string, tag = "1")]
pub text: ::prost::alloc::string::String,
/// Monotonically increasing within a session, starting at 1.
#[prost(uint64, tag = "2")]
pub revision: u64,
}
#[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
pub struct TranscriptionDone {
#[prost(string, tag = "1")]
pub text: ::prost::alloc::string::String,
/// See TranscriptionResponse.language. Reported under either output
/// contract.
#[prost(message, optional, tag = "2")]
pub language: ::core::option::Option<ResolvedLanguage>,
/// The revision of the final hypothesis under
/// STREAMING_OUTPUT_CONTRACT_REVISED_HYPOTHESES; zero under the
/// append-fragment contract.
#[prost(uint64, tag = "3")]
pub revision: u64,
}
#[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
pub struct SpeechWebSocketRequest {
#[prost(oneof = "speech_web_socket_request::Payload", tags = "1, 2, 3, 4")]
pub payload: ::core::option::Option<speech_web_socket_request::Payload>,
}
/// Nested message and enum types in `SpeechWebSocketRequest`.
pub mod speech_web_socket_request {
#[derive(Clone, PartialEq, Eq, Hash, ::prost::Oneof)]
pub enum Payload {
#[prost(message, tag = "1")]
Start(super::StreamingConfig),
#[prost(bytes, tag = "2")]
Audio(::prost::alloc::vec::Vec<u8>),
#[prost(message, tag = "3")]
End(super::SpeechWebSocketEnd),
#[prost(message, tag = "4")]
Cancel(super::SpeechWebSocketCancel),
}
}
#[derive(Clone, Copy, PartialEq, Eq, Hash, ::prost::Message)]
pub struct SpeechWebSocketEnd {}
#[derive(Clone, Copy, PartialEq, Eq, Hash, ::prost::Message)]
pub struct SpeechWebSocketCancel {}
#[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
pub struct SpeechWebSocketResponse {
#[prost(oneof = "speech_web_socket_response::Payload", tags = "1, 2, 3, 4, 5, 6")]
pub payload: ::core::option::Option<speech_web_socket_response::Payload>,
}
/// Nested message and enum types in `SpeechWebSocketResponse`.
pub mod speech_web_socket_response {
#[derive(Clone, PartialEq, Eq, Hash, ::prost::Oneof)]
pub enum Payload {
#[prost(message, tag = "1")]
Started(super::SpeechWebSocketStarted),
#[prost(message, tag = "2")]
Delta(super::TranscriptionDelta),
#[prost(message, tag = "3")]
Done(super::TranscriptionDone),
#[prost(message, tag = "4")]
Error(super::SpeechWebSocketError),
#[prost(message, tag = "5")]
Cancelled(super::SpeechWebSocketCancelled),
/// Full-hypothesis partial under
/// STREAMING_OUTPUT_CONTRACT_REVISED_HYPOTHESES; see
/// TranscriptionHypothesis.
#[prost(message, tag = "6")]
Hypothesis(super::TranscriptionHypothesis),
}
}
#[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
pub struct SpeechWebSocketStarted {
#[prost(string, tag = "1")]
pub request_id: ::prost::alloc::string::String,
/// Confirms STREAMING_OUTPUT_CONTRACT_APPEND_FRAGMENTS or
/// STREAMING_OUTPUT_CONTRACT_REVISED_HYPOTHESES before any audio-derived
/// response. Present for every accepted configuration.
#[prost(message, optional, tag = "2")]
pub accepted: ::core::option::Option<StreamingAccepted>,
}
#[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
pub struct SpeechWebSocketError {
/// Stable public category such as invalid_input, resource_exhausted,
/// unavailable, timeout, cancelled, or internal.
#[prost(string, tag = "1")]
pub kind: ::prost::alloc::string::String,
/// Human-readable diagnostic; clients branch on `kind`, not this text.
#[prost(string, tag = "2")]
pub message: ::prost::alloc::string::String,
#[prost(string, optional, tag = "3")]
pub request_id: ::core::option::Option<::prost::alloc::string::String>,
}
/// Acknowledges an explicit `cancel`. Closing the connection instead also
/// cancels its associated backend work, but cannot carry this acknowledgement.
#[derive(Clone, Copy, PartialEq, Eq, Hash, ::prost::Message)]
pub struct SpeechWebSocketCancelled {}
/// Output formatting intent. The packaged model prompt describes the intent;
/// it steers the model rather than hard-guaranteeing token-level behavior.
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, ::prost::Enumeration)]
#[repr(i32)]
pub enum TranscriptionMode {
/// Defaults to TRANSCRIPTION_MODE_WRITTEN.
Unspecified = 0,
/// Standard written formatting: numerals as digits, codes compact.
/// "flight two four seven" is intended to come back as "flight 247".
Written = 1,
/// Verbatim rendering: keep every filler, repetition, and false start;
/// numbers as spoken words. "uh flight two four seven" is intended to come
/// back as "uh flight two four seven".
Verbatim = 2,
}
impl TranscriptionMode {
/// String value of the enum field names used in the ProtoBuf definition.
///
/// The values are not transformed in any way and thus are considered stable
/// (if the ProtoBuf definition does not change) and safe for programmatic use.
pub fn as_str_name(&self) -> &'static str {
match self {
Self::Unspecified => "TRANSCRIPTION_MODE_UNSPECIFIED",
Self::Written => "TRANSCRIPTION_MODE_WRITTEN",
Self::Verbatim => "TRANSCRIPTION_MODE_VERBATIM",
}
}
/// Creates an enum from field names used in the ProtoBuf definition.
pub fn from_str_name(value: &str) -> ::core::option::Option<Self> {
match value {
"TRANSCRIPTION_MODE_UNSPECIFIED" => Some(Self::Unspecified),
"TRANSCRIPTION_MODE_WRITTEN" => Some(Self::Written),
"TRANSCRIPTION_MODE_VERBATIM" => Some(Self::Verbatim),
_ => None,
}
}
}
/// How the resolved language was chosen.
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, ::prost::Enumeration)]
#[repr(i32)]
pub enum LanguageSource {
/// The service could not resolve a catalog language for this result. Never
/// a silent substitute for LANGUAGE_SOURCE_SELECTED or
/// LANGUAGE_SOURCE_DETECTED.
Unspecified = 0,
/// The caller supplied the language and the service confirmed it against
/// the packaged model catalog.
Selected = 1,
/// The model detected the served catalog language. Not produced while every
/// request must select its language.
Detected = 2,
}
impl LanguageSource {
/// String value of the enum field names used in the ProtoBuf definition.
///
/// The values are not transformed in any way and thus are considered stable
/// (if the ProtoBuf definition does not change) and safe for programmatic use.
pub fn as_str_name(&self) -> &'static str {
match self {
Self::Unspecified => "LANGUAGE_SOURCE_UNSPECIFIED",
Self::Selected => "LANGUAGE_SOURCE_SELECTED",
Self::Detected => "LANGUAGE_SOURCE_DETECTED",
}
}
/// Creates an enum from field names used in the ProtoBuf definition.
pub fn from_str_name(value: &str) -> ::core::option::Option<Self> {
match value {
"LANGUAGE_SOURCE_UNSPECIFIED" => Some(Self::Unspecified),
"LANGUAGE_SOURCE_SELECTED" => Some(Self::Selected),
"LANGUAGE_SOURCE_DETECTED" => Some(Self::Detected),
_ => None,
}
}
}
/// Which streaming output contract the session uses.
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, ::prost::Enumeration)]
#[repr(i32)]
pub enum StreamingOutputContract {
/// Invalid for a request: callers must explicitly select an output contract.
Unspecified = 0,
/// Responses are append-only `delta` fragments: each five-second window of
/// audio is transcribed once, on its own, so a fragment is never revised.
/// Concatenate them in arrival order (including newline separators between
/// transcription windows) to form the transcript. The final `done` text
/// equals that concatenation.
AppendFragments = 1,
/// Responses are full replacing `hypothesis` transcripts: each hypothesis
/// carries the complete current transcript and a monotonically increasing
/// revision, and entirely replaces the previous one. The final `done` text
/// equals the last hypothesis and carries its revision; an utterance with
/// no recognized speech may emit no hypothesis and finishes with an empty
/// final at revision zero.
RevisedHypotheses = 2,
}
impl StreamingOutputContract {
/// String value of the enum field names used in the ProtoBuf definition.
///
/// The values are not transformed in any way and thus are considered stable
/// (if the ProtoBuf definition does not change) and safe for programmatic use.
pub fn as_str_name(&self) -> &'static str {
match self {
Self::Unspecified => "STREAMING_OUTPUT_CONTRACT_UNSPECIFIED",
Self::AppendFragments => "STREAMING_OUTPUT_CONTRACT_APPEND_FRAGMENTS",
Self::RevisedHypotheses => "STREAMING_OUTPUT_CONTRACT_REVISED_HYPOTHESES",
}
}
/// Creates an enum from field names used in the ProtoBuf definition.
pub fn from_str_name(value: &str) -> ::core::option::Option<Self> {
match value {
"STREAMING_OUTPUT_CONTRACT_UNSPECIFIED" => Some(Self::Unspecified),
"STREAMING_OUTPUT_CONTRACT_APPEND_FRAGMENTS" => Some(Self::AppendFragments),
"STREAMING_OUTPUT_CONTRACT_REVISED_HYPOTHESES" => {
Some(Self::RevisedHypotheses)
}
_ => None,
}
}
}
/// Generated client implementations.
#[cfg(feature = "grpc")]
pub mod speech_to_text_client {
#![allow(
unused_variables,
dead_code,
missing_docs,
clippy::wildcard_imports,
clippy::let_unit_value,
)]
use tonic::codegen::*;
use tonic::codegen::http::Uri;
/// Whole-utterance and realtime speech recognition for Cassowary. Cassowary
/// adapts this public contract to the native vLLM chat API; vLLM owns model
/// loading, inference, and GPU scheduling.
#[derive(Debug, Clone)]
pub struct SpeechToTextClient<T> {
inner: tonic::client::Grpc<T>,
}
impl SpeechToTextClient<tonic::transport::Channel> {
/// Attempt to create a new client by connecting to a given endpoint.
pub async fn connect<D>(dst: D) -> Result<Self, tonic::transport::Error>
where
D: TryInto<tonic::transport::Endpoint>,
D::Error: Into<StdError>,
{
let conn = tonic::transport::Endpoint::new(dst)?.connect().await?;
Ok(Self::new(conn))
}
}
impl<T> SpeechToTextClient<T>
where
T: tonic::client::GrpcService<tonic::body::Body>,
T::Error: Into<StdError>,
T::ResponseBody: Body<Data = Bytes> + std::marker::Send + 'static,
<T::ResponseBody as Body>::Error: Into<StdError> + std::marker::Send,
{
pub fn new(inner: T) -> Self {
let inner = tonic::client::Grpc::new(inner);
Self { inner }
}
pub fn with_origin(inner: T, origin: Uri) -> Self {
let inner = tonic::client::Grpc::with_origin(inner, origin);
Self { inner }
}
pub fn with_interceptor<F>(
inner: T,
interceptor: F,
) -> SpeechToTextClient<InterceptedService<T, F>>
where
F: tonic::service::Interceptor,
T::ResponseBody: Default,
T: tonic::codegen::Service<
http::Request<tonic::body::Body>,
Response = http::Response<
<T as tonic::client::GrpcService<tonic::body::Body>>::ResponseBody,
>,
>,
<T as tonic::codegen::Service<
http::Request<tonic::body::Body>,
>>::Error: Into<StdError> + std::marker::Send + std::marker::Sync,
{
SpeechToTextClient::new(InterceptedService::new(inner, interceptor))
}
/// Compress requests with the given encoding.
///
/// This requires the server to support it otherwise it might respond with an
/// error.
#[must_use]
pub fn send_compressed(mut self, encoding: CompressionEncoding) -> Self {
self.inner = self.inner.send_compressed(encoding);
self
}
/// Enable decompressing responses.
#[must_use]
pub fn accept_compressed(mut self, encoding: CompressionEncoding) -> Self {
self.inner = self.inner.accept_compressed(encoding);
self
}
/// Limits the maximum size of a decoded message.
///
/// Default: `4MB`
#[must_use]
pub fn max_decoding_message_size(mut self, limit: usize) -> Self {
self.inner = self.inner.max_decoding_message_size(limit);
self
}
/// Limits the maximum size of an encoded message.
///
/// Default: `usize::MAX`
#[must_use]
pub fn max_encoding_message_size(mut self, limit: usize) -> Self {
self.inner = self.inner.max_encoding_message_size(limit);
self
}
/// Transcribes one complete WAV payload. Language and formatting mode are
/// available for the whole-utterance model path.
pub async fn transcribe(
&mut self,
request: impl tonic::IntoRequest<super::TranscriptionRequest>,
) -> std::result::Result<
tonic::Response<super::TranscriptionResponse>,
tonic::Status,
> {
self.inner
.ready()
.await
.map_err(|e| {
tonic::Status::unknown(
format!("Service was not ready: {}", e.into()),
)
})?;
let codec = tonic_prost::ProstCodec::default();
let path = http::uri::PathAndQuery::from_static(
"/rime.SpeechToText/Transcribe",
);
let mut req = request.into_request();
req.extensions_mut()
.insert(GrpcMethod::new("rime.SpeechToText", "Transcribe"));
self.inner.unary(req, path, codec).await
}
/// Transcribes exactly one realtime PCM16 mono 16 kHz utterance per client
/// stream. The first request must contain `config`; following requests contain
/// audio. Client half-close commits the utterance and produces one final `done`
/// response. Dropping either side of the RPC cancels the associated backend
/// work.
pub async fn transcribe_streaming(
&mut self,
request: impl tonic::IntoStreamingRequest<
Message = super::StreamingTranscriptionRequest,
>,
) -> std::result::Result<
tonic::Response<
tonic::codec::Streaming<super::StreamingTranscriptionResponse>,
>,
tonic::Status,
> {
self.inner
.ready()
.await
.map_err(|e| {
tonic::Status::unknown(
format!("Service was not ready: {}", e.into()),
)
})?;
let codec = tonic_prost::ProstCodec::default();
let path = http::uri::PathAndQuery::from_static(
"/rime.SpeechToText/TranscribeStreaming",
);
let mut req = request.into_streaming_request();
req.extensions_mut()
.insert(GrpcMethod::new("rime.SpeechToText", "TranscribeStreaming"));
self.inner.streaming(req, path, codec).await
}
}
}
/// Generated server implementations.
#[cfg(feature = "grpc")]
pub mod speech_to_text_server {
#![allow(
unused_variables,
dead_code,
missing_docs,
clippy::wildcard_imports,
clippy::let_unit_value,
)]
use tonic::codegen::*;
/// Generated trait containing gRPC methods that should be implemented for use with SpeechToTextServer.
#[async_trait]
pub trait SpeechToText: std::marker::Send + std::marker::Sync + 'static {
/// Transcribes one complete WAV payload. Language and formatting mode are
/// available for the whole-utterance model path.
async fn transcribe(
&self,
request: tonic::Request<super::TranscriptionRequest>,
) -> std::result::Result<
tonic::Response<super::TranscriptionResponse>,
tonic::Status,
>;
/// Server streaming response type for the TranscribeStreaming method.
type TranscribeStreamingStream: tonic::codegen::tokio_stream::Stream<
Item = std::result::Result<
super::StreamingTranscriptionResponse,
tonic::Status,
>,
>
+ std::marker::Send
+ 'static;
/// Transcribes exactly one realtime PCM16 mono 16 kHz utterance per client
/// stream. The first request must contain `config`; following requests contain
/// audio. Client half-close commits the utterance and produces one final `done`
/// response. Dropping either side of the RPC cancels the associated backend
/// work.
async fn transcribe_streaming(
&self,
request: tonic::Request<
tonic::Streaming<super::StreamingTranscriptionRequest>,
>,
) -> std::result::Result<
tonic::Response<Self::TranscribeStreamingStream>,
tonic::Status,
>;
}
/// Whole-utterance and realtime speech recognition for Cassowary. Cassowary
/// adapts this public contract to the native vLLM chat API; vLLM owns model
/// loading, inference, and GPU scheduling.
#[derive(Debug)]
pub struct SpeechToTextServer<T> {
inner: Arc<T>,
accept_compression_encodings: EnabledCompressionEncodings,
send_compression_encodings: EnabledCompressionEncodings,
max_decoding_message_size: Option<usize>,
max_encoding_message_size: Option<usize>,
}
impl<T> SpeechToTextServer<T> {
pub fn new(inner: T) -> Self {
Self::from_arc(Arc::new(inner))
}
pub fn from_arc(inner: Arc<T>) -> Self {
Self {
inner,
accept_compression_encodings: Default::default(),
send_compression_encodings: Default::default(),
max_decoding_message_size: None,
max_encoding_message_size: None,
}
}
pub fn with_interceptor<F>(
inner: T,
interceptor: F,
) -> InterceptedService<Self, F>
where
F: tonic::service::Interceptor,
{
InterceptedService::new(Self::new(inner), interceptor)
}
/// Enable decompressing requests with the given encoding.
#[must_use]
pub fn accept_compressed(mut self, encoding: CompressionEncoding) -> Self {
self.accept_compression_encodings.enable(encoding);
self
}
/// Compress responses with the given encoding, if the client supports it.
#[must_use]
pub fn send_compressed(mut self, encoding: CompressionEncoding) -> Self {
self.send_compression_encodings.enable(encoding);
self
}
/// Limits the maximum size of a decoded message.
///
/// Default: `4MB`
#[must_use]
pub fn max_decoding_message_size(mut self, limit: usize) -> Self {
self.max_decoding_message_size = Some(limit);
self
}
/// Limits the maximum size of an encoded message.
///
/// Default: `usize::MAX`
#[must_use]
pub fn max_encoding_message_size(mut self, limit: usize) -> Self {
self.max_encoding_message_size = Some(limit);
self
}
}
impl<T, B> tonic::codegen::Service<http::Request<B>> for SpeechToTextServer<T>
where
T: SpeechToText,
B: Body + std::marker::Send + 'static,
B::Error: Into<StdError> + std::marker::Send + 'static,
{
type Response = http::Response<tonic::body::Body>;
type Error = std::convert::Infallible;
type Future = BoxFuture<Self::Response, Self::Error>;
fn poll_ready(
&mut self,
_cx: &mut Context<'_>,
) -> Poll<std::result::Result<(), Self::Error>> {
Poll::Ready(Ok(()))
}
fn call(&mut self, req: http::Request<B>) -> Self::Future {
match req.uri().path() {
"/rime.SpeechToText/Transcribe" => {
#[allow(non_camel_case_types)]
struct TranscribeSvc<T: SpeechToText>(pub Arc<T>);
impl<
T: SpeechToText,
> tonic::server::UnaryService<super::TranscriptionRequest>
for TranscribeSvc<T> {
type Response = super::TranscriptionResponse;
type Future = BoxFuture<
tonic::Response<Self::Response>,
tonic::Status,
>;
fn call(
&mut self,
request: tonic::Request<super::TranscriptionRequest>,
) -> Self::Future {
let inner = Arc::clone(&self.0);
let fut = async move {
<T as SpeechToText>::transcribe(&inner, request).await
};
Box::pin(fut)
}
}
let accept_compression_encodings = self.accept_compression_encodings;
let send_compression_encodings = self.send_compression_encodings;
let max_decoding_message_size = self.max_decoding_message_size;
let max_encoding_message_size = self.max_encoding_message_size;
let inner = self.inner.clone();
let fut = async move {
let method = TranscribeSvc(inner);
let codec = tonic_prost::ProstCodec::default();
let mut grpc = tonic::server::Grpc::new(codec)
.apply_compression_config(
accept_compression_encodings,
send_compression_encodings,
)
.apply_max_message_size_config(
max_decoding_message_size,
max_encoding_message_size,
);
let res = grpc.unary(method, req).await;
Ok(res)
};
Box::pin(fut)
}
"/rime.SpeechToText/TranscribeStreaming" => {
#[allow(non_camel_case_types)]
struct TranscribeStreamingSvc<T: SpeechToText>(pub Arc<T>);
impl<
T: SpeechToText,
> tonic::server::StreamingService<
super::StreamingTranscriptionRequest,
> for TranscribeStreamingSvc<T> {
type Response = super::StreamingTranscriptionResponse;
type ResponseStream = T::TranscribeStreamingStream;
type Future = BoxFuture<
tonic::Response<Self::ResponseStream>,
tonic::Status,
>;
fn call(
&mut self,
request: tonic::Request<
tonic::Streaming<super::StreamingTranscriptionRequest>,
>,
) -> Self::Future {
let inner = Arc::clone(&self.0);
let fut = async move {
<T as SpeechToText>::transcribe_streaming(&inner, request)
.await
};
Box::pin(fut)
}
}
let accept_compression_encodings = self.accept_compression_encodings;
let send_compression_encodings = self.send_compression_encodings;
let max_decoding_message_size = self.max_decoding_message_size;
let max_encoding_message_size = self.max_encoding_message_size;
let inner = self.inner.clone();
let fut = async move {
let method = TranscribeStreamingSvc(inner);
let codec = tonic_prost::ProstCodec::default();
let mut grpc = tonic::server::Grpc::new(codec)
.apply_compression_config(
accept_compression_encodings,
send_compression_encodings,
)
.apply_max_message_size_config(
max_decoding_message_size,
max_encoding_message_size,
);
let res = grpc.streaming(method, req).await;
Ok(res)
};
Box::pin(fut)
}
_ => {
Box::pin(async move {
let mut response = http::Response::new(
tonic::body::Body::default(),
);
let headers = response.headers_mut();
headers
.insert(
tonic::Status::GRPC_STATUS,
(tonic::Code::Unimplemented as i32).into(),
);
headers
.insert(
http::header::CONTENT_TYPE,
tonic::metadata::GRPC_CONTENT_TYPE,
);
Ok(response)
})
}
}
}
}
impl<T> Clone for SpeechToTextServer<T> {
fn clone(&self) -> Self {
let inner = self.inner.clone();
Self {
inner,
accept_compression_encodings: self.accept_compression_encodings,
send_compression_encodings: self.send_compression_encodings,
max_decoding_message_size: self.max_decoding_message_size,
max_encoding_message_size: self.max_encoding_message_size,
}
}
}
/// Generated gRPC service name
pub const SERVICE_NAME: &str = "rime.SpeechToText";
impl<T> tonic::server::NamedService for SpeechToTextServer<T> {
const NAME: &'static str = SERVICE_NAME;
}
}