1#[derive(Clone, PartialEq, ::prost::Message)]
3pub struct StreamingSynthesisRequest {
4 #[prost(oneof = "streaming_synthesis_request::Payload", tags = "1, 2")]
5 pub payload: ::core::option::Option<streaming_synthesis_request::Payload>,
6}
7pub mod streaming_synthesis_request {
9 #[derive(Clone, PartialEq, ::prost::Oneof)]
10 pub enum Payload {
11 #[prost(message, tag = "1")]
14 Header(super::SynthesisRequest),
15 #[prost(string, tag = "2")]
18 TextChunk(::prost::alloc::string::String),
19 }
20}
21#[derive(Clone, PartialEq, ::prost::Message)]
22pub struct SynthesisRequest {
23 #[prost(string, optional, tag = "2")]
26 pub language: ::core::option::Option<::prost::alloc::string::String>,
27 #[prost(string, optional, tag = "3")]
29 pub speaker: ::core::option::Option<::prost::alloc::string::String>,
30 #[prost(string, tag = "4")]
32 pub text: ::prost::alloc::string::String,
33 #[prost(message, optional, tag = "5")]
34 pub audio_parameters: ::core::option::Option<AudioParameters>,
35 #[prost(enumeration = "SplitStrategy", optional, tag = "6")]
38 pub split_strategy: ::core::option::Option<i32>,
39 #[prost(message, optional, tag = "8")]
40 pub coda_parameters: ::core::option::Option<CodaParameters>,
41 #[prost(message, optional, tag = "9")]
42 pub mist_parameters: ::core::option::Option<MistParameters>,
43 #[prost(message, optional, tag = "10")]
46 pub timestamps: ::core::option::Option<TimestampOptions>,
47 #[prost(message, repeated, tag = "11")]
52 pub custom_lexicon: ::prost::alloc::vec::Vec<PronunciationEntry>,
53}
54#[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
58pub struct PronunciationEntry {
59 #[prost(string, tag = "1")]
61 pub spelling: ::prost::alloc::string::String,
62 #[prost(string, tag = "2")]
64 pub pronunciation: ::prost::alloc::string::String,
65}
66#[derive(Clone, PartialEq, ::prost::Message)]
67pub struct SynthesisResponseStream {
68 #[prost(oneof = "synthesis_response_stream::Payload", tags = "1, 2")]
69 pub payload: ::core::option::Option<synthesis_response_stream::Payload>,
70}
71pub mod synthesis_response_stream {
73 #[derive(Clone, PartialEq, ::prost::Oneof)]
74 pub enum Payload {
75 #[prost(bytes, tag = "1")]
77 Audio(::prost::alloc::vec::Vec<u8>),
78 #[prost(message, tag = "2")]
81 Trailer(super::SynthesisResponseTrailer),
82 }
83}
84#[derive(Clone, PartialEq, ::prost::Message)]
86pub struct SynthesisResponseTrailer {
87 #[prost(message, optional, tag = "1")]
89 pub timestamps: ::core::option::Option<Timestamps>,
90}
91#[derive(Clone, PartialEq, ::prost::Message)]
92pub struct AudioParameters {
93 #[prost(string, optional, tag = "1")]
96 pub audio_format: ::core::option::Option<::prost::alloc::string::String>,
97 #[prost(int32, optional, tag = "2")]
98 pub sampling_rate: ::core::option::Option<i32>,
99 #[prost(float, optional, tag = "3")]
100 pub time_scale_factor: ::core::option::Option<f32>,
101}
102#[derive(Clone, Copy, PartialEq, Eq, Hash, ::prost::Message)]
103pub struct CodaParameters {
104 #[prost(int32, optional, tag = "8")]
113 pub text_lookahead_tokens: ::core::option::Option<i32>,
114}
115#[derive(Clone, PartialEq, ::prost::Message)]
116pub struct MistParameters {
117 #[prost(bool, optional, tag = "1")]
118 pub pause_between_brackets: ::core::option::Option<bool>,
119 #[prost(bool, optional, tag = "2")]
120 pub phonemize_between_brackets: ::core::option::Option<bool>,
121 #[prost(float, repeated, tag = "3")]
122 pub inline_time_scale_factors: ::prost::alloc::vec::Vec<f32>,
123 #[prost(bool, optional, tag = "4")]
124 pub save_oovs: ::core::option::Option<bool>,
125}
126#[derive(Clone, Copy, PartialEq, Eq, Hash, ::prost::Message)]
127pub struct TimestampOptions {
128 #[prost(bool, tag = "1")]
131 pub enable: bool,
132}
133#[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
138pub struct SpanTimestamp {
139 #[prost(string, tag = "1")]
140 pub text: ::prost::alloc::string::String,
141 #[prost(message, optional, tag = "2")]
144 pub start: ::core::option::Option<::pbjson_types::Duration>,
145 #[prost(message, optional, tag = "3")]
146 pub end: ::core::option::Option<::pbjson_types::Duration>,
147}
148#[derive(Clone, PartialEq, ::prost::Message)]
153pub struct Timestamps {
154 #[prost(message, optional, tag = "1")]
165 pub status: ::core::option::Option<super::google::rpc::Status>,
166 #[prost(message, repeated, tag = "2")]
167 pub spans: ::prost::alloc::vec::Vec<SpanTimestamp>,
168}
169#[derive(Clone, PartialEq, ::prost::Message)]
170pub struct NormalizeTextRequest {
171 #[prost(string, tag = "1")]
173 pub text: ::prost::alloc::string::String,
174 #[prost(string, optional, tag = "2")]
176 pub language: ::core::option::Option<::prost::alloc::string::String>,
177 #[prost(message, repeated, tag = "3")]
180 pub custom_lexicon: ::prost::alloc::vec::Vec<PronunciationEntry>,
181}
182#[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
183pub struct NormalizeTextResponse {
184 #[prost(string, tag = "1")]
187 pub normalized_text: ::prost::alloc::string::String,
188 #[prost(string, repeated, tag = "2")]
192 pub normalized_sentences: ::prost::alloc::vec::Vec<::prost::alloc::string::String>,
193}
194#[derive(Clone, Copy, PartialEq, Eq, Hash, ::prost::Message)]
196pub struct GetSupportedLanguagesRequest {}
197#[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
198pub struct GetSupportedLanguagesResponse {
199 #[prost(string, repeated, tag = "1")]
201 pub languages: ::prost::alloc::vec::Vec<::prost::alloc::string::String>,
202}
203#[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
204pub struct GetSupportedSpeakersRequest {
205 #[prost(string, optional, tag = "1")]
206 pub language: ::core::option::Option<::prost::alloc::string::String>,
207}
208#[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
209pub struct GetSupportedSpeakersResponse {
210 #[prost(string, repeated, tag = "1")]
212 pub speakers: ::prost::alloc::vec::Vec<::prost::alloc::string::String>,
213}
214#[derive(Clone, PartialEq, ::prost::Message)]
216pub struct WebSocketRequest {
217 #[prost(string, tag = "1")]
221 pub context_id: ::prost::alloc::string::String,
222 #[prost(oneof = "web_socket_request::Payload", tags = "2, 3, 4, 5, 6")]
223 pub payload: ::core::option::Option<web_socket_request::Payload>,
224}
225pub mod web_socket_request {
227 #[derive(Clone, PartialEq, ::prost::Oneof)]
228 pub enum Payload {
229 #[prost(message, tag = "2")]
233 Config(super::WebSocketConfig),
234 #[prost(message, tag = "3")]
240 Start(super::SynthesisRequest),
241 #[prost(string, tag = "4")]
247 Text(::prost::alloc::string::String),
248 #[prost(message, tag = "5")]
252 End(super::WebSocketEnd),
253 #[prost(message, tag = "6")]
257 Cancel(super::WebSocketCancel),
258 }
259}
260#[derive(Clone, PartialEq, ::prost::Message)]
261pub struct WebSocketConfig {
262 #[prost(string, optional, tag = "1")]
265 pub authorization: ::core::option::Option<::prost::alloc::string::String>,
266 #[prost(string, optional, tag = "2")]
269 pub license: ::core::option::Option<::prost::alloc::string::String>,
270 #[prost(message, optional, tag = "3")]
273 pub defaults: ::core::option::Option<SynthesisRequest>,
274}
275#[derive(Clone, Copy, PartialEq, Eq, Hash, ::prost::Message)]
276pub struct WebSocketEnd {}
277#[derive(Clone, Copy, PartialEq, Eq, Hash, ::prost::Message)]
278pub struct WebSocketCancel {}
279#[derive(Clone, PartialEq, ::prost::Message)]
281pub struct WebSocketResponse {
282 #[prost(string, tag = "1")]
285 pub context_id: ::prost::alloc::string::String,
286 #[prost(oneof = "web_socket_response::Payload", tags = "2, 3, 4, 5, 6, 7")]
287 pub payload: ::core::option::Option<web_socket_response::Payload>,
288}
289pub mod web_socket_response {
291 #[derive(Clone, PartialEq, ::prost::Oneof)]
292 pub enum Payload {
293 #[prost(message, tag = "2")]
296 Ready(super::WebSocketReady),
297 #[prost(message, tag = "3")]
299 Started(super::WebSocketStarted),
300 #[prost(bytes, tag = "4")]
302 Audio(::prost::alloc::vec::Vec<u8>),
303 #[prost(message, tag = "5")]
305 Done(super::WebSocketDone),
306 #[prost(message, tag = "6")]
308 Cancelled(super::WebSocketCancelled),
309 #[prost(message, tag = "7")]
314 Error(super::WebSocketError),
315 }
316}
317#[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
318pub struct WebSocketReady {
319 #[prost(uint32, tag = "1")]
321 pub protocol: u32,
322 #[prost(string, repeated, tag = "2")]
324 pub languages: ::prost::alloc::vec::Vec<::prost::alloc::string::String>,
325 #[prost(string, optional, tag = "3")]
326 pub default_language: ::core::option::Option<::prost::alloc::string::String>,
327}
328#[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
329pub struct WebSocketStarted {
330 #[prost(string, tag = "1")]
333 pub request_id: ::prost::alloc::string::String,
334}
335#[derive(Clone, PartialEq, ::prost::Message)]
336pub struct WebSocketDone {
337 #[prost(message, optional, tag = "1")]
339 pub timestamps: ::core::option::Option<Timestamps>,
340}
341#[derive(Clone, Copy, PartialEq, Eq, Hash, ::prost::Message)]
342pub struct WebSocketCancelled {}
343#[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
344pub struct WebSocketError {
345 #[prost(string, tag = "1")]
349 pub kind: ::prost::alloc::string::String,
350 #[prost(string, tag = "2")]
352 pub message: ::prost::alloc::string::String,
353 #[prost(string, optional, tag = "3")]
355 pub request_id: ::core::option::Option<::prost::alloc::string::String>,
356}
357#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, ::prost::Enumeration)]
358#[repr(i32)]
359pub enum SplitStrategy {
360 Unspecified = 0,
361 Sentence = 1,
362 None = 2,
363 AccumulateSentence = 3,
368}
369impl SplitStrategy {
370 pub fn as_str_name(&self) -> &'static str {
375 match self {
376 Self::Unspecified => "SPLIT_STRATEGY_UNSPECIFIED",
377 Self::Sentence => "SPLIT_STRATEGY_SENTENCE",
378 Self::None => "SPLIT_STRATEGY_NONE",
379 Self::AccumulateSentence => "SPLIT_STRATEGY_ACCUMULATE_SENTENCE",
380 }
381 }
382 pub fn from_str_name(value: &str) -> ::core::option::Option<Self> {
384 match value {
385 "SPLIT_STRATEGY_UNSPECIFIED" => Some(Self::Unspecified),
386 "SPLIT_STRATEGY_SENTENCE" => Some(Self::Sentence),
387 "SPLIT_STRATEGY_NONE" => Some(Self::None),
388 "SPLIT_STRATEGY_ACCUMULATE_SENTENCE" => Some(Self::AccumulateSentence),
389 _ => None,
390 }
391 }
392}
393#[cfg(feature = "grpc")]
395pub mod text_to_speech_client {
396 #![allow(
397 unused_variables,
398 dead_code,
399 missing_docs,
400 clippy::wildcard_imports,
401 clippy::let_unit_value,
402 )]
403 use tonic::codegen::*;
404 use tonic::codegen::http::Uri;
405 #[derive(Debug, Clone)]
406 pub struct TextToSpeechClient<T> {
407 inner: tonic::client::Grpc<T>,
408 }
409 impl TextToSpeechClient<tonic::transport::Channel> {
410 pub async fn connect<D>(dst: D) -> Result<Self, tonic::transport::Error>
412 where
413 D: TryInto<tonic::transport::Endpoint>,
414 D::Error: Into<StdError>,
415 {
416 let conn = tonic::transport::Endpoint::new(dst)?.connect().await?;
417 Ok(Self::new(conn))
418 }
419 }
420 impl<T> TextToSpeechClient<T>
421 where
422 T: tonic::client::GrpcService<tonic::body::Body>,
423 T::Error: Into<StdError>,
424 T::ResponseBody: Body<Data = Bytes> + std::marker::Send + 'static,
425 <T::ResponseBody as Body>::Error: Into<StdError> + std::marker::Send,
426 {
427 pub fn new(inner: T) -> Self {
428 let inner = tonic::client::Grpc::new(inner);
429 Self { inner }
430 }
431 pub fn with_origin(inner: T, origin: Uri) -> Self {
432 let inner = tonic::client::Grpc::with_origin(inner, origin);
433 Self { inner }
434 }
435 pub fn with_interceptor<F>(
436 inner: T,
437 interceptor: F,
438 ) -> TextToSpeechClient<InterceptedService<T, F>>
439 where
440 F: tonic::service::Interceptor,
441 T::ResponseBody: Default,
442 T: tonic::codegen::Service<
443 http::Request<tonic::body::Body>,
444 Response = http::Response<
445 <T as tonic::client::GrpcService<tonic::body::Body>>::ResponseBody,
446 >,
447 >,
448 <T as tonic::codegen::Service<
449 http::Request<tonic::body::Body>,
450 >>::Error: Into<StdError> + std::marker::Send + std::marker::Sync,
451 {
452 TextToSpeechClient::new(InterceptedService::new(inner, interceptor))
453 }
454 #[must_use]
459 pub fn send_compressed(mut self, encoding: CompressionEncoding) -> Self {
460 self.inner = self.inner.send_compressed(encoding);
461 self
462 }
463 #[must_use]
465 pub fn accept_compressed(mut self, encoding: CompressionEncoding) -> Self {
466 self.inner = self.inner.accept_compressed(encoding);
467 self
468 }
469 #[must_use]
473 pub fn max_decoding_message_size(mut self, limit: usize) -> Self {
474 self.inner = self.inner.max_decoding_message_size(limit);
475 self
476 }
477 #[must_use]
481 pub fn max_encoding_message_size(mut self, limit: usize) -> Self {
482 self.inner = self.inner.max_encoding_message_size(limit);
483 self
484 }
485 pub async fn synthesize(
486 &mut self,
487 request: impl tonic::IntoRequest<super::SynthesisRequest>,
488 ) -> std::result::Result<
489 tonic::Response<tonic::codec::Streaming<super::SynthesisResponseStream>>,
490 tonic::Status,
491 > {
492 self.inner
493 .ready()
494 .await
495 .map_err(|e| {
496 tonic::Status::unknown(
497 format!("Service was not ready: {}", e.into()),
498 )
499 })?;
500 let codec = tonic_prost::ProstCodec::default();
501 let path = http::uri::PathAndQuery::from_static(
502 "/rime.TextToSpeech/Synthesize",
503 );
504 let mut req = request.into_request();
505 req.extensions_mut()
506 .insert(GrpcMethod::new("rime.TextToSpeech", "Synthesize"));
507 self.inner.server_streaming(req, path, codec).await
508 }
509 pub async fn synthesize_streaming(
516 &mut self,
517 request: impl tonic::IntoStreamingRequest<
518 Message = super::StreamingSynthesisRequest,
519 >,
520 ) -> std::result::Result<
521 tonic::Response<tonic::codec::Streaming<super::SynthesisResponseStream>>,
522 tonic::Status,
523 > {
524 self.inner
525 .ready()
526 .await
527 .map_err(|e| {
528 tonic::Status::unknown(
529 format!("Service was not ready: {}", e.into()),
530 )
531 })?;
532 let codec = tonic_prost::ProstCodec::default();
533 let path = http::uri::PathAndQuery::from_static(
534 "/rime.TextToSpeech/SynthesizeStreaming",
535 );
536 let mut req = request.into_streaming_request();
537 req.extensions_mut()
538 .insert(GrpcMethod::new("rime.TextToSpeech", "SynthesizeStreaming"));
539 self.inner.streaming(req, path, codec).await
540 }
541 pub async fn normalize_text(
542 &mut self,
543 request: impl tonic::IntoRequest<super::NormalizeTextRequest>,
544 ) -> std::result::Result<
545 tonic::Response<super::NormalizeTextResponse>,
546 tonic::Status,
547 > {
548 self.inner
549 .ready()
550 .await
551 .map_err(|e| {
552 tonic::Status::unknown(
553 format!("Service was not ready: {}", e.into()),
554 )
555 })?;
556 let codec = tonic_prost::ProstCodec::default();
557 let path = http::uri::PathAndQuery::from_static(
558 "/rime.TextToSpeech/NormalizeText",
559 );
560 let mut req = request.into_request();
561 req.extensions_mut()
562 .insert(GrpcMethod::new("rime.TextToSpeech", "NormalizeText"));
563 self.inner.unary(req, path, codec).await
564 }
565 pub async fn get_supported_languages(
566 &mut self,
567 request: impl tonic::IntoRequest<super::GetSupportedLanguagesRequest>,
568 ) -> std::result::Result<
569 tonic::Response<super::GetSupportedLanguagesResponse>,
570 tonic::Status,
571 > {
572 self.inner
573 .ready()
574 .await
575 .map_err(|e| {
576 tonic::Status::unknown(
577 format!("Service was not ready: {}", e.into()),
578 )
579 })?;
580 let codec = tonic_prost::ProstCodec::default();
581 let path = http::uri::PathAndQuery::from_static(
582 "/rime.TextToSpeech/GetSupportedLanguages",
583 );
584 let mut req = request.into_request();
585 req.extensions_mut()
586 .insert(GrpcMethod::new("rime.TextToSpeech", "GetSupportedLanguages"));
587 self.inner.unary(req, path, codec).await
588 }
589 pub async fn get_supported_speakers(
590 &mut self,
591 request: impl tonic::IntoRequest<super::GetSupportedSpeakersRequest>,
592 ) -> std::result::Result<
593 tonic::Response<super::GetSupportedSpeakersResponse>,
594 tonic::Status,
595 > {
596 self.inner
597 .ready()
598 .await
599 .map_err(|e| {
600 tonic::Status::unknown(
601 format!("Service was not ready: {}", e.into()),
602 )
603 })?;
604 let codec = tonic_prost::ProstCodec::default();
605 let path = http::uri::PathAndQuery::from_static(
606 "/rime.TextToSpeech/GetSupportedSpeakers",
607 );
608 let mut req = request.into_request();
609 req.extensions_mut()
610 .insert(GrpcMethod::new("rime.TextToSpeech", "GetSupportedSpeakers"));
611 self.inner.unary(req, path, codec).await
612 }
613 }
614}
615#[cfg(feature = "grpc")]
617pub mod text_to_speech_server {
618 #![allow(
619 unused_variables,
620 dead_code,
621 missing_docs,
622 clippy::wildcard_imports,
623 clippy::let_unit_value,
624 )]
625 use tonic::codegen::*;
626 #[async_trait]
628 pub trait TextToSpeech: std::marker::Send + std::marker::Sync + 'static {
629 type SynthesizeStream: tonic::codegen::tokio_stream::Stream<
631 Item = std::result::Result<super::SynthesisResponseStream, tonic::Status>,
632 >
633 + std::marker::Send
634 + 'static;
635 async fn synthesize(
636 &self,
637 request: tonic::Request<super::SynthesisRequest>,
638 ) -> std::result::Result<tonic::Response<Self::SynthesizeStream>, tonic::Status>;
639 type SynthesizeStreamingStream: tonic::codegen::tokio_stream::Stream<
641 Item = std::result::Result<super::SynthesisResponseStream, tonic::Status>,
642 >
643 + std::marker::Send
644 + 'static;
645 async fn synthesize_streaming(
652 &self,
653 request: tonic::Request<tonic::Streaming<super::StreamingSynthesisRequest>>,
654 ) -> std::result::Result<
655 tonic::Response<Self::SynthesizeStreamingStream>,
656 tonic::Status,
657 >;
658 async fn normalize_text(
659 &self,
660 request: tonic::Request<super::NormalizeTextRequest>,
661 ) -> std::result::Result<
662 tonic::Response<super::NormalizeTextResponse>,
663 tonic::Status,
664 >;
665 async fn get_supported_languages(
666 &self,
667 request: tonic::Request<super::GetSupportedLanguagesRequest>,
668 ) -> std::result::Result<
669 tonic::Response<super::GetSupportedLanguagesResponse>,
670 tonic::Status,
671 >;
672 async fn get_supported_speakers(
673 &self,
674 request: tonic::Request<super::GetSupportedSpeakersRequest>,
675 ) -> std::result::Result<
676 tonic::Response<super::GetSupportedSpeakersResponse>,
677 tonic::Status,
678 >;
679 }
680 #[derive(Debug)]
681 pub struct TextToSpeechServer<T> {
682 inner: Arc<T>,
683 accept_compression_encodings: EnabledCompressionEncodings,
684 send_compression_encodings: EnabledCompressionEncodings,
685 max_decoding_message_size: Option<usize>,
686 max_encoding_message_size: Option<usize>,
687 }
688 impl<T> TextToSpeechServer<T> {
689 pub fn new(inner: T) -> Self {
690 Self::from_arc(Arc::new(inner))
691 }
692 pub fn from_arc(inner: Arc<T>) -> Self {
693 Self {
694 inner,
695 accept_compression_encodings: Default::default(),
696 send_compression_encodings: Default::default(),
697 max_decoding_message_size: None,
698 max_encoding_message_size: None,
699 }
700 }
701 pub fn with_interceptor<F>(
702 inner: T,
703 interceptor: F,
704 ) -> InterceptedService<Self, F>
705 where
706 F: tonic::service::Interceptor,
707 {
708 InterceptedService::new(Self::new(inner), interceptor)
709 }
710 #[must_use]
712 pub fn accept_compressed(mut self, encoding: CompressionEncoding) -> Self {
713 self.accept_compression_encodings.enable(encoding);
714 self
715 }
716 #[must_use]
718 pub fn send_compressed(mut self, encoding: CompressionEncoding) -> Self {
719 self.send_compression_encodings.enable(encoding);
720 self
721 }
722 #[must_use]
726 pub fn max_decoding_message_size(mut self, limit: usize) -> Self {
727 self.max_decoding_message_size = Some(limit);
728 self
729 }
730 #[must_use]
734 pub fn max_encoding_message_size(mut self, limit: usize) -> Self {
735 self.max_encoding_message_size = Some(limit);
736 self
737 }
738 }
739 impl<T, B> tonic::codegen::Service<http::Request<B>> for TextToSpeechServer<T>
740 where
741 T: TextToSpeech,
742 B: Body + std::marker::Send + 'static,
743 B::Error: Into<StdError> + std::marker::Send + 'static,
744 {
745 type Response = http::Response<tonic::body::Body>;
746 type Error = std::convert::Infallible;
747 type Future = BoxFuture<Self::Response, Self::Error>;
748 fn poll_ready(
749 &mut self,
750 _cx: &mut Context<'_>,
751 ) -> Poll<std::result::Result<(), Self::Error>> {
752 Poll::Ready(Ok(()))
753 }
754 fn call(&mut self, req: http::Request<B>) -> Self::Future {
755 match req.uri().path() {
756 "/rime.TextToSpeech/Synthesize" => {
757 #[allow(non_camel_case_types)]
758 struct SynthesizeSvc<T: TextToSpeech>(pub Arc<T>);
759 impl<
760 T: TextToSpeech,
761 > tonic::server::ServerStreamingService<super::SynthesisRequest>
762 for SynthesizeSvc<T> {
763 type Response = super::SynthesisResponseStream;
764 type ResponseStream = T::SynthesizeStream;
765 type Future = BoxFuture<
766 tonic::Response<Self::ResponseStream>,
767 tonic::Status,
768 >;
769 fn call(
770 &mut self,
771 request: tonic::Request<super::SynthesisRequest>,
772 ) -> Self::Future {
773 let inner = Arc::clone(&self.0);
774 let fut = async move {
775 <T as TextToSpeech>::synthesize(&inner, request).await
776 };
777 Box::pin(fut)
778 }
779 }
780 let accept_compression_encodings = self.accept_compression_encodings;
781 let send_compression_encodings = self.send_compression_encodings;
782 let max_decoding_message_size = self.max_decoding_message_size;
783 let max_encoding_message_size = self.max_encoding_message_size;
784 let inner = self.inner.clone();
785 let fut = async move {
786 let method = SynthesizeSvc(inner);
787 let codec = tonic_prost::ProstCodec::default();
788 let mut grpc = tonic::server::Grpc::new(codec)
789 .apply_compression_config(
790 accept_compression_encodings,
791 send_compression_encodings,
792 )
793 .apply_max_message_size_config(
794 max_decoding_message_size,
795 max_encoding_message_size,
796 );
797 let res = grpc.server_streaming(method, req).await;
798 Ok(res)
799 };
800 Box::pin(fut)
801 }
802 "/rime.TextToSpeech/SynthesizeStreaming" => {
803 #[allow(non_camel_case_types)]
804 struct SynthesizeStreamingSvc<T: TextToSpeech>(pub Arc<T>);
805 impl<
806 T: TextToSpeech,
807 > tonic::server::StreamingService<super::StreamingSynthesisRequest>
808 for SynthesizeStreamingSvc<T> {
809 type Response = super::SynthesisResponseStream;
810 type ResponseStream = T::SynthesizeStreamingStream;
811 type Future = BoxFuture<
812 tonic::Response<Self::ResponseStream>,
813 tonic::Status,
814 >;
815 fn call(
816 &mut self,
817 request: tonic::Request<
818 tonic::Streaming<super::StreamingSynthesisRequest>,
819 >,
820 ) -> Self::Future {
821 let inner = Arc::clone(&self.0);
822 let fut = async move {
823 <T as TextToSpeech>::synthesize_streaming(&inner, request)
824 .await
825 };
826 Box::pin(fut)
827 }
828 }
829 let accept_compression_encodings = self.accept_compression_encodings;
830 let send_compression_encodings = self.send_compression_encodings;
831 let max_decoding_message_size = self.max_decoding_message_size;
832 let max_encoding_message_size = self.max_encoding_message_size;
833 let inner = self.inner.clone();
834 let fut = async move {
835 let method = SynthesizeStreamingSvc(inner);
836 let codec = tonic_prost::ProstCodec::default();
837 let mut grpc = tonic::server::Grpc::new(codec)
838 .apply_compression_config(
839 accept_compression_encodings,
840 send_compression_encodings,
841 )
842 .apply_max_message_size_config(
843 max_decoding_message_size,
844 max_encoding_message_size,
845 );
846 let res = grpc.streaming(method, req).await;
847 Ok(res)
848 };
849 Box::pin(fut)
850 }
851 "/rime.TextToSpeech/NormalizeText" => {
852 #[allow(non_camel_case_types)]
853 struct NormalizeTextSvc<T: TextToSpeech>(pub Arc<T>);
854 impl<
855 T: TextToSpeech,
856 > tonic::server::UnaryService<super::NormalizeTextRequest>
857 for NormalizeTextSvc<T> {
858 type Response = super::NormalizeTextResponse;
859 type Future = BoxFuture<
860 tonic::Response<Self::Response>,
861 tonic::Status,
862 >;
863 fn call(
864 &mut self,
865 request: tonic::Request<super::NormalizeTextRequest>,
866 ) -> Self::Future {
867 let inner = Arc::clone(&self.0);
868 let fut = async move {
869 <T as TextToSpeech>::normalize_text(&inner, request).await
870 };
871 Box::pin(fut)
872 }
873 }
874 let accept_compression_encodings = self.accept_compression_encodings;
875 let send_compression_encodings = self.send_compression_encodings;
876 let max_decoding_message_size = self.max_decoding_message_size;
877 let max_encoding_message_size = self.max_encoding_message_size;
878 let inner = self.inner.clone();
879 let fut = async move {
880 let method = NormalizeTextSvc(inner);
881 let codec = tonic_prost::ProstCodec::default();
882 let mut grpc = tonic::server::Grpc::new(codec)
883 .apply_compression_config(
884 accept_compression_encodings,
885 send_compression_encodings,
886 )
887 .apply_max_message_size_config(
888 max_decoding_message_size,
889 max_encoding_message_size,
890 );
891 let res = grpc.unary(method, req).await;
892 Ok(res)
893 };
894 Box::pin(fut)
895 }
896 "/rime.TextToSpeech/GetSupportedLanguages" => {
897 #[allow(non_camel_case_types)]
898 struct GetSupportedLanguagesSvc<T: TextToSpeech>(pub Arc<T>);
899 impl<
900 T: TextToSpeech,
901 > tonic::server::UnaryService<super::GetSupportedLanguagesRequest>
902 for GetSupportedLanguagesSvc<T> {
903 type Response = super::GetSupportedLanguagesResponse;
904 type Future = BoxFuture<
905 tonic::Response<Self::Response>,
906 tonic::Status,
907 >;
908 fn call(
909 &mut self,
910 request: tonic::Request<super::GetSupportedLanguagesRequest>,
911 ) -> Self::Future {
912 let inner = Arc::clone(&self.0);
913 let fut = async move {
914 <T as TextToSpeech>::get_supported_languages(
915 &inner,
916 request,
917 )
918 .await
919 };
920 Box::pin(fut)
921 }
922 }
923 let accept_compression_encodings = self.accept_compression_encodings;
924 let send_compression_encodings = self.send_compression_encodings;
925 let max_decoding_message_size = self.max_decoding_message_size;
926 let max_encoding_message_size = self.max_encoding_message_size;
927 let inner = self.inner.clone();
928 let fut = async move {
929 let method = GetSupportedLanguagesSvc(inner);
930 let codec = tonic_prost::ProstCodec::default();
931 let mut grpc = tonic::server::Grpc::new(codec)
932 .apply_compression_config(
933 accept_compression_encodings,
934 send_compression_encodings,
935 )
936 .apply_max_message_size_config(
937 max_decoding_message_size,
938 max_encoding_message_size,
939 );
940 let res = grpc.unary(method, req).await;
941 Ok(res)
942 };
943 Box::pin(fut)
944 }
945 "/rime.TextToSpeech/GetSupportedSpeakers" => {
946 #[allow(non_camel_case_types)]
947 struct GetSupportedSpeakersSvc<T: TextToSpeech>(pub Arc<T>);
948 impl<
949 T: TextToSpeech,
950 > tonic::server::UnaryService<super::GetSupportedSpeakersRequest>
951 for GetSupportedSpeakersSvc<T> {
952 type Response = super::GetSupportedSpeakersResponse;
953 type Future = BoxFuture<
954 tonic::Response<Self::Response>,
955 tonic::Status,
956 >;
957 fn call(
958 &mut self,
959 request: tonic::Request<super::GetSupportedSpeakersRequest>,
960 ) -> Self::Future {
961 let inner = Arc::clone(&self.0);
962 let fut = async move {
963 <T as TextToSpeech>::get_supported_speakers(&inner, request)
964 .await
965 };
966 Box::pin(fut)
967 }
968 }
969 let accept_compression_encodings = self.accept_compression_encodings;
970 let send_compression_encodings = self.send_compression_encodings;
971 let max_decoding_message_size = self.max_decoding_message_size;
972 let max_encoding_message_size = self.max_encoding_message_size;
973 let inner = self.inner.clone();
974 let fut = async move {
975 let method = GetSupportedSpeakersSvc(inner);
976 let codec = tonic_prost::ProstCodec::default();
977 let mut grpc = tonic::server::Grpc::new(codec)
978 .apply_compression_config(
979 accept_compression_encodings,
980 send_compression_encodings,
981 )
982 .apply_max_message_size_config(
983 max_decoding_message_size,
984 max_encoding_message_size,
985 );
986 let res = grpc.unary(method, req).await;
987 Ok(res)
988 };
989 Box::pin(fut)
990 }
991 _ => {
992 Box::pin(async move {
993 let mut response = http::Response::new(
994 tonic::body::Body::default(),
995 );
996 let headers = response.headers_mut();
997 headers
998 .insert(
999 tonic::Status::GRPC_STATUS,
1000 (tonic::Code::Unimplemented as i32).into(),
1001 );
1002 headers
1003 .insert(
1004 http::header::CONTENT_TYPE,
1005 tonic::metadata::GRPC_CONTENT_TYPE,
1006 );
1007 Ok(response)
1008 })
1009 }
1010 }
1011 }
1012 }
1013 impl<T> Clone for TextToSpeechServer<T> {
1014 fn clone(&self) -> Self {
1015 let inner = self.inner.clone();
1016 Self {
1017 inner,
1018 accept_compression_encodings: self.accept_compression_encodings,
1019 send_compression_encodings: self.send_compression_encodings,
1020 max_decoding_message_size: self.max_decoding_message_size,
1021 max_encoding_message_size: self.max_encoding_message_size,
1022 }
1023 }
1024 }
1025 pub const SERVICE_NAME: &str = "rime.TextToSpeech";
1027 impl<T> tonic::server::NamedService for TextToSpeechServer<T> {
1028 const NAME: &'static str = SERVICE_NAME;
1029 }
1030}
1031#[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
1032pub struct TranscriptionOptions {
1033 #[prost(string, optional, tag = "1")]
1037 pub language: ::core::option::Option<::prost::alloc::string::String>,
1038 #[prost(enumeration = "TranscriptionMode", tag = "2")]
1039 pub mode: i32,
1040 #[prost(string, repeated, tag = "3")]
1049 pub context_terms: ::prost::alloc::vec::Vec<::prost::alloc::string::String>,
1050}
1051#[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
1052pub struct ResolvedLanguage {
1053 #[prost(string, tag = "1")]
1055 pub tag: ::prost::alloc::string::String,
1056 #[prost(enumeration = "LanguageSource", tag = "2")]
1057 pub source: i32,
1058}
1059#[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
1060pub struct TranscriptionRequest {
1061 #[prost(bytes = "vec", tag = "1")]
1066 pub audio: ::prost::alloc::vec::Vec<u8>,
1067 #[prost(message, optional, tag = "2")]
1069 pub options: ::core::option::Option<TranscriptionOptions>,
1070}
1071#[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
1072pub struct TranscriptionResponse {
1073 #[prost(string, tag = "1")]
1074 pub text: ::prost::alloc::string::String,
1075 #[prost(message, optional, tag = "2")]
1077 pub language: ::core::option::Option<ResolvedLanguage>,
1078}
1079#[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
1082pub struct StreamingConfig {
1083 #[prost(string, optional, tag = "3")]
1087 pub language: ::core::option::Option<::prost::alloc::string::String>,
1088 #[prost(enumeration = "TranscriptionMode", tag = "4")]
1089 pub mode: i32,
1090 #[prost(enumeration = "StreamingOutputContract", tag = "5")]
1094 pub output_contract: i32,
1095 #[prost(string, repeated, tag = "6")]
1099 pub context_terms: ::prost::alloc::vec::Vec<::prost::alloc::string::String>,
1100}
1101#[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
1102pub struct StreamingTranscriptionRequest {
1103 #[prost(oneof = "streaming_transcription_request::Payload", tags = "1, 2")]
1104 pub payload: ::core::option::Option<streaming_transcription_request::Payload>,
1105}
1106pub mod streaming_transcription_request {
1108 #[derive(Clone, PartialEq, Eq, Hash, ::prost::Oneof)]
1109 pub enum Payload {
1110 #[prost(message, tag = "1")]
1112 Config(super::StreamingConfig),
1113 #[prost(bytes, tag = "2")]
1116 Audio(::prost::alloc::vec::Vec<u8>),
1117 }
1118}
1119#[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
1120pub struct StreamingTranscriptionResponse {
1121 #[prost(oneof = "streaming_transcription_response::Payload", tags = "1, 2, 3, 4")]
1122 pub payload: ::core::option::Option<streaming_transcription_response::Payload>,
1123}
1124pub mod streaming_transcription_response {
1126 #[derive(Clone, PartialEq, Eq, Hash, ::prost::Oneof)]
1127 pub enum Payload {
1128 #[prost(message, tag = "1")]
1132 Delta(super::TranscriptionDelta),
1133 #[prost(message, tag = "2")]
1140 Done(super::TranscriptionDone),
1141 #[prost(message, tag = "3")]
1147 Accepted(super::StreamingAccepted),
1148 #[prost(message, tag = "4")]
1152 Hypothesis(super::TranscriptionHypothesis),
1153 }
1154}
1155#[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
1156pub struct StreamingAccepted {
1157 #[prost(enumeration = "StreamingOutputContract", tag = "1")]
1158 pub output_contract: i32,
1159 #[prost(message, optional, tag = "2")]
1161 pub language: ::core::option::Option<ResolvedLanguage>,
1162}
1163#[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
1164pub struct TranscriptionDelta {
1165 #[prost(string, tag = "1")]
1166 pub text: ::prost::alloc::string::String,
1167}
1168#[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
1171pub struct TranscriptionHypothesis {
1172 #[prost(string, tag = "1")]
1173 pub text: ::prost::alloc::string::String,
1174 #[prost(uint64, tag = "2")]
1176 pub revision: u64,
1177}
1178#[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
1179pub struct TranscriptionDone {
1180 #[prost(string, tag = "1")]
1181 pub text: ::prost::alloc::string::String,
1182 #[prost(message, optional, tag = "2")]
1185 pub language: ::core::option::Option<ResolvedLanguage>,
1186 #[prost(uint64, tag = "3")]
1190 pub revision: u64,
1191}
1192#[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
1193pub struct SpeechWebSocketRequest {
1194 #[prost(oneof = "speech_web_socket_request::Payload", tags = "1, 2, 3, 4")]
1195 pub payload: ::core::option::Option<speech_web_socket_request::Payload>,
1196}
1197pub mod speech_web_socket_request {
1199 #[derive(Clone, PartialEq, Eq, Hash, ::prost::Oneof)]
1200 pub enum Payload {
1201 #[prost(message, tag = "1")]
1202 Start(super::StreamingConfig),
1203 #[prost(bytes, tag = "2")]
1204 Audio(::prost::alloc::vec::Vec<u8>),
1205 #[prost(message, tag = "3")]
1206 End(super::SpeechWebSocketEnd),
1207 #[prost(message, tag = "4")]
1208 Cancel(super::SpeechWebSocketCancel),
1209 }
1210}
1211#[derive(Clone, Copy, PartialEq, Eq, Hash, ::prost::Message)]
1212pub struct SpeechWebSocketEnd {}
1213#[derive(Clone, Copy, PartialEq, Eq, Hash, ::prost::Message)]
1214pub struct SpeechWebSocketCancel {}
1215#[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
1216pub struct SpeechWebSocketResponse {
1217 #[prost(oneof = "speech_web_socket_response::Payload", tags = "1, 2, 3, 4, 5, 6")]
1218 pub payload: ::core::option::Option<speech_web_socket_response::Payload>,
1219}
1220pub mod speech_web_socket_response {
1222 #[derive(Clone, PartialEq, Eq, Hash, ::prost::Oneof)]
1223 pub enum Payload {
1224 #[prost(message, tag = "1")]
1225 Started(super::SpeechWebSocketStarted),
1226 #[prost(message, tag = "2")]
1227 Delta(super::TranscriptionDelta),
1228 #[prost(message, tag = "3")]
1229 Done(super::TranscriptionDone),
1230 #[prost(message, tag = "4")]
1231 Error(super::SpeechWebSocketError),
1232 #[prost(message, tag = "5")]
1233 Cancelled(super::SpeechWebSocketCancelled),
1234 #[prost(message, tag = "6")]
1238 Hypothesis(super::TranscriptionHypothesis),
1239 }
1240}
1241#[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
1242pub struct SpeechWebSocketStarted {
1243 #[prost(string, tag = "1")]
1244 pub request_id: ::prost::alloc::string::String,
1245 #[prost(message, optional, tag = "2")]
1249 pub accepted: ::core::option::Option<StreamingAccepted>,
1250}
1251#[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
1252pub struct SpeechWebSocketError {
1253 #[prost(string, tag = "1")]
1256 pub kind: ::prost::alloc::string::String,
1257 #[prost(string, tag = "2")]
1259 pub message: ::prost::alloc::string::String,
1260 #[prost(string, optional, tag = "3")]
1261 pub request_id: ::core::option::Option<::prost::alloc::string::String>,
1262}
1263#[derive(Clone, Copy, PartialEq, Eq, Hash, ::prost::Message)]
1266pub struct SpeechWebSocketCancelled {}
1267#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, ::prost::Enumeration)]
1270#[repr(i32)]
1271pub enum TranscriptionMode {
1272 Unspecified = 0,
1274 Written = 1,
1277 Verbatim = 2,
1281}
1282impl TranscriptionMode {
1283 pub fn as_str_name(&self) -> &'static str {
1288 match self {
1289 Self::Unspecified => "TRANSCRIPTION_MODE_UNSPECIFIED",
1290 Self::Written => "TRANSCRIPTION_MODE_WRITTEN",
1291 Self::Verbatim => "TRANSCRIPTION_MODE_VERBATIM",
1292 }
1293 }
1294 pub fn from_str_name(value: &str) -> ::core::option::Option<Self> {
1296 match value {
1297 "TRANSCRIPTION_MODE_UNSPECIFIED" => Some(Self::Unspecified),
1298 "TRANSCRIPTION_MODE_WRITTEN" => Some(Self::Written),
1299 "TRANSCRIPTION_MODE_VERBATIM" => Some(Self::Verbatim),
1300 _ => None,
1301 }
1302 }
1303}
1304#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, ::prost::Enumeration)]
1306#[repr(i32)]
1307pub enum LanguageSource {
1308 Unspecified = 0,
1312 Selected = 1,
1315 Detected = 2,
1318}
1319impl LanguageSource {
1320 pub fn as_str_name(&self) -> &'static str {
1325 match self {
1326 Self::Unspecified => "LANGUAGE_SOURCE_UNSPECIFIED",
1327 Self::Selected => "LANGUAGE_SOURCE_SELECTED",
1328 Self::Detected => "LANGUAGE_SOURCE_DETECTED",
1329 }
1330 }
1331 pub fn from_str_name(value: &str) -> ::core::option::Option<Self> {
1333 match value {
1334 "LANGUAGE_SOURCE_UNSPECIFIED" => Some(Self::Unspecified),
1335 "LANGUAGE_SOURCE_SELECTED" => Some(Self::Selected),
1336 "LANGUAGE_SOURCE_DETECTED" => Some(Self::Detected),
1337 _ => None,
1338 }
1339 }
1340}
1341#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, ::prost::Enumeration)]
1343#[repr(i32)]
1344pub enum StreamingOutputContract {
1345 Unspecified = 0,
1347 AppendFragments = 1,
1353 RevisedHypotheses = 2,
1360}
1361impl StreamingOutputContract {
1362 pub fn as_str_name(&self) -> &'static str {
1367 match self {
1368 Self::Unspecified => "STREAMING_OUTPUT_CONTRACT_UNSPECIFIED",
1369 Self::AppendFragments => "STREAMING_OUTPUT_CONTRACT_APPEND_FRAGMENTS",
1370 Self::RevisedHypotheses => "STREAMING_OUTPUT_CONTRACT_REVISED_HYPOTHESES",
1371 }
1372 }
1373 pub fn from_str_name(value: &str) -> ::core::option::Option<Self> {
1375 match value {
1376 "STREAMING_OUTPUT_CONTRACT_UNSPECIFIED" => Some(Self::Unspecified),
1377 "STREAMING_OUTPUT_CONTRACT_APPEND_FRAGMENTS" => Some(Self::AppendFragments),
1378 "STREAMING_OUTPUT_CONTRACT_REVISED_HYPOTHESES" => {
1379 Some(Self::RevisedHypotheses)
1380 }
1381 _ => None,
1382 }
1383 }
1384}
1385#[cfg(feature = "grpc")]
1387pub mod speech_to_text_client {
1388 #![allow(
1389 unused_variables,
1390 dead_code,
1391 missing_docs,
1392 clippy::wildcard_imports,
1393 clippy::let_unit_value,
1394 )]
1395 use tonic::codegen::*;
1396 use tonic::codegen::http::Uri;
1397 #[derive(Debug, Clone)]
1401 pub struct SpeechToTextClient<T> {
1402 inner: tonic::client::Grpc<T>,
1403 }
1404 impl SpeechToTextClient<tonic::transport::Channel> {
1405 pub async fn connect<D>(dst: D) -> Result<Self, tonic::transport::Error>
1407 where
1408 D: TryInto<tonic::transport::Endpoint>,
1409 D::Error: Into<StdError>,
1410 {
1411 let conn = tonic::transport::Endpoint::new(dst)?.connect().await?;
1412 Ok(Self::new(conn))
1413 }
1414 }
1415 impl<T> SpeechToTextClient<T>
1416 where
1417 T: tonic::client::GrpcService<tonic::body::Body>,
1418 T::Error: Into<StdError>,
1419 T::ResponseBody: Body<Data = Bytes> + std::marker::Send + 'static,
1420 <T::ResponseBody as Body>::Error: Into<StdError> + std::marker::Send,
1421 {
1422 pub fn new(inner: T) -> Self {
1423 let inner = tonic::client::Grpc::new(inner);
1424 Self { inner }
1425 }
1426 pub fn with_origin(inner: T, origin: Uri) -> Self {
1427 let inner = tonic::client::Grpc::with_origin(inner, origin);
1428 Self { inner }
1429 }
1430 pub fn with_interceptor<F>(
1431 inner: T,
1432 interceptor: F,
1433 ) -> SpeechToTextClient<InterceptedService<T, F>>
1434 where
1435 F: tonic::service::Interceptor,
1436 T::ResponseBody: Default,
1437 T: tonic::codegen::Service<
1438 http::Request<tonic::body::Body>,
1439 Response = http::Response<
1440 <T as tonic::client::GrpcService<tonic::body::Body>>::ResponseBody,
1441 >,
1442 >,
1443 <T as tonic::codegen::Service<
1444 http::Request<tonic::body::Body>,
1445 >>::Error: Into<StdError> + std::marker::Send + std::marker::Sync,
1446 {
1447 SpeechToTextClient::new(InterceptedService::new(inner, interceptor))
1448 }
1449 #[must_use]
1454 pub fn send_compressed(mut self, encoding: CompressionEncoding) -> Self {
1455 self.inner = self.inner.send_compressed(encoding);
1456 self
1457 }
1458 #[must_use]
1460 pub fn accept_compressed(mut self, encoding: CompressionEncoding) -> Self {
1461 self.inner = self.inner.accept_compressed(encoding);
1462 self
1463 }
1464 #[must_use]
1468 pub fn max_decoding_message_size(mut self, limit: usize) -> Self {
1469 self.inner = self.inner.max_decoding_message_size(limit);
1470 self
1471 }
1472 #[must_use]
1476 pub fn max_encoding_message_size(mut self, limit: usize) -> Self {
1477 self.inner = self.inner.max_encoding_message_size(limit);
1478 self
1479 }
1480 pub async fn transcribe(
1483 &mut self,
1484 request: impl tonic::IntoRequest<super::TranscriptionRequest>,
1485 ) -> std::result::Result<
1486 tonic::Response<super::TranscriptionResponse>,
1487 tonic::Status,
1488 > {
1489 self.inner
1490 .ready()
1491 .await
1492 .map_err(|e| {
1493 tonic::Status::unknown(
1494 format!("Service was not ready: {}", e.into()),
1495 )
1496 })?;
1497 let codec = tonic_prost::ProstCodec::default();
1498 let path = http::uri::PathAndQuery::from_static(
1499 "/rime.SpeechToText/Transcribe",
1500 );
1501 let mut req = request.into_request();
1502 req.extensions_mut()
1503 .insert(GrpcMethod::new("rime.SpeechToText", "Transcribe"));
1504 self.inner.unary(req, path, codec).await
1505 }
1506 pub async fn transcribe_streaming(
1512 &mut self,
1513 request: impl tonic::IntoStreamingRequest<
1514 Message = super::StreamingTranscriptionRequest,
1515 >,
1516 ) -> std::result::Result<
1517 tonic::Response<
1518 tonic::codec::Streaming<super::StreamingTranscriptionResponse>,
1519 >,
1520 tonic::Status,
1521 > {
1522 self.inner
1523 .ready()
1524 .await
1525 .map_err(|e| {
1526 tonic::Status::unknown(
1527 format!("Service was not ready: {}", e.into()),
1528 )
1529 })?;
1530 let codec = tonic_prost::ProstCodec::default();
1531 let path = http::uri::PathAndQuery::from_static(
1532 "/rime.SpeechToText/TranscribeStreaming",
1533 );
1534 let mut req = request.into_streaming_request();
1535 req.extensions_mut()
1536 .insert(GrpcMethod::new("rime.SpeechToText", "TranscribeStreaming"));
1537 self.inner.streaming(req, path, codec).await
1538 }
1539 }
1540}
1541#[cfg(feature = "grpc")]
1543pub mod speech_to_text_server {
1544 #![allow(
1545 unused_variables,
1546 dead_code,
1547 missing_docs,
1548 clippy::wildcard_imports,
1549 clippy::let_unit_value,
1550 )]
1551 use tonic::codegen::*;
1552 #[async_trait]
1554 pub trait SpeechToText: std::marker::Send + std::marker::Sync + 'static {
1555 async fn transcribe(
1558 &self,
1559 request: tonic::Request<super::TranscriptionRequest>,
1560 ) -> std::result::Result<
1561 tonic::Response<super::TranscriptionResponse>,
1562 tonic::Status,
1563 >;
1564 type TranscribeStreamingStream: tonic::codegen::tokio_stream::Stream<
1566 Item = std::result::Result<
1567 super::StreamingTranscriptionResponse,
1568 tonic::Status,
1569 >,
1570 >
1571 + std::marker::Send
1572 + 'static;
1573 async fn transcribe_streaming(
1579 &self,
1580 request: tonic::Request<
1581 tonic::Streaming<super::StreamingTranscriptionRequest>,
1582 >,
1583 ) -> std::result::Result<
1584 tonic::Response<Self::TranscribeStreamingStream>,
1585 tonic::Status,
1586 >;
1587 }
1588 #[derive(Debug)]
1592 pub struct SpeechToTextServer<T> {
1593 inner: Arc<T>,
1594 accept_compression_encodings: EnabledCompressionEncodings,
1595 send_compression_encodings: EnabledCompressionEncodings,
1596 max_decoding_message_size: Option<usize>,
1597 max_encoding_message_size: Option<usize>,
1598 }
1599 impl<T> SpeechToTextServer<T> {
1600 pub fn new(inner: T) -> Self {
1601 Self::from_arc(Arc::new(inner))
1602 }
1603 pub fn from_arc(inner: Arc<T>) -> Self {
1604 Self {
1605 inner,
1606 accept_compression_encodings: Default::default(),
1607 send_compression_encodings: Default::default(),
1608 max_decoding_message_size: None,
1609 max_encoding_message_size: None,
1610 }
1611 }
1612 pub fn with_interceptor<F>(
1613 inner: T,
1614 interceptor: F,
1615 ) -> InterceptedService<Self, F>
1616 where
1617 F: tonic::service::Interceptor,
1618 {
1619 InterceptedService::new(Self::new(inner), interceptor)
1620 }
1621 #[must_use]
1623 pub fn accept_compressed(mut self, encoding: CompressionEncoding) -> Self {
1624 self.accept_compression_encodings.enable(encoding);
1625 self
1626 }
1627 #[must_use]
1629 pub fn send_compressed(mut self, encoding: CompressionEncoding) -> Self {
1630 self.send_compression_encodings.enable(encoding);
1631 self
1632 }
1633 #[must_use]
1637 pub fn max_decoding_message_size(mut self, limit: usize) -> Self {
1638 self.max_decoding_message_size = Some(limit);
1639 self
1640 }
1641 #[must_use]
1645 pub fn max_encoding_message_size(mut self, limit: usize) -> Self {
1646 self.max_encoding_message_size = Some(limit);
1647 self
1648 }
1649 }
1650 impl<T, B> tonic::codegen::Service<http::Request<B>> for SpeechToTextServer<T>
1651 where
1652 T: SpeechToText,
1653 B: Body + std::marker::Send + 'static,
1654 B::Error: Into<StdError> + std::marker::Send + 'static,
1655 {
1656 type Response = http::Response<tonic::body::Body>;
1657 type Error = std::convert::Infallible;
1658 type Future = BoxFuture<Self::Response, Self::Error>;
1659 fn poll_ready(
1660 &mut self,
1661 _cx: &mut Context<'_>,
1662 ) -> Poll<std::result::Result<(), Self::Error>> {
1663 Poll::Ready(Ok(()))
1664 }
1665 fn call(&mut self, req: http::Request<B>) -> Self::Future {
1666 match req.uri().path() {
1667 "/rime.SpeechToText/Transcribe" => {
1668 #[allow(non_camel_case_types)]
1669 struct TranscribeSvc<T: SpeechToText>(pub Arc<T>);
1670 impl<
1671 T: SpeechToText,
1672 > tonic::server::UnaryService<super::TranscriptionRequest>
1673 for TranscribeSvc<T> {
1674 type Response = super::TranscriptionResponse;
1675 type Future = BoxFuture<
1676 tonic::Response<Self::Response>,
1677 tonic::Status,
1678 >;
1679 fn call(
1680 &mut self,
1681 request: tonic::Request<super::TranscriptionRequest>,
1682 ) -> Self::Future {
1683 let inner = Arc::clone(&self.0);
1684 let fut = async move {
1685 <T as SpeechToText>::transcribe(&inner, request).await
1686 };
1687 Box::pin(fut)
1688 }
1689 }
1690 let accept_compression_encodings = self.accept_compression_encodings;
1691 let send_compression_encodings = self.send_compression_encodings;
1692 let max_decoding_message_size = self.max_decoding_message_size;
1693 let max_encoding_message_size = self.max_encoding_message_size;
1694 let inner = self.inner.clone();
1695 let fut = async move {
1696 let method = TranscribeSvc(inner);
1697 let codec = tonic_prost::ProstCodec::default();
1698 let mut grpc = tonic::server::Grpc::new(codec)
1699 .apply_compression_config(
1700 accept_compression_encodings,
1701 send_compression_encodings,
1702 )
1703 .apply_max_message_size_config(
1704 max_decoding_message_size,
1705 max_encoding_message_size,
1706 );
1707 let res = grpc.unary(method, req).await;
1708 Ok(res)
1709 };
1710 Box::pin(fut)
1711 }
1712 "/rime.SpeechToText/TranscribeStreaming" => {
1713 #[allow(non_camel_case_types)]
1714 struct TranscribeStreamingSvc<T: SpeechToText>(pub Arc<T>);
1715 impl<
1716 T: SpeechToText,
1717 > tonic::server::StreamingService<
1718 super::StreamingTranscriptionRequest,
1719 > for TranscribeStreamingSvc<T> {
1720 type Response = super::StreamingTranscriptionResponse;
1721 type ResponseStream = T::TranscribeStreamingStream;
1722 type Future = BoxFuture<
1723 tonic::Response<Self::ResponseStream>,
1724 tonic::Status,
1725 >;
1726 fn call(
1727 &mut self,
1728 request: tonic::Request<
1729 tonic::Streaming<super::StreamingTranscriptionRequest>,
1730 >,
1731 ) -> Self::Future {
1732 let inner = Arc::clone(&self.0);
1733 let fut = async move {
1734 <T as SpeechToText>::transcribe_streaming(&inner, request)
1735 .await
1736 };
1737 Box::pin(fut)
1738 }
1739 }
1740 let accept_compression_encodings = self.accept_compression_encodings;
1741 let send_compression_encodings = self.send_compression_encodings;
1742 let max_decoding_message_size = self.max_decoding_message_size;
1743 let max_encoding_message_size = self.max_encoding_message_size;
1744 let inner = self.inner.clone();
1745 let fut = async move {
1746 let method = TranscribeStreamingSvc(inner);
1747 let codec = tonic_prost::ProstCodec::default();
1748 let mut grpc = tonic::server::Grpc::new(codec)
1749 .apply_compression_config(
1750 accept_compression_encodings,
1751 send_compression_encodings,
1752 )
1753 .apply_max_message_size_config(
1754 max_decoding_message_size,
1755 max_encoding_message_size,
1756 );
1757 let res = grpc.streaming(method, req).await;
1758 Ok(res)
1759 };
1760 Box::pin(fut)
1761 }
1762 _ => {
1763 Box::pin(async move {
1764 let mut response = http::Response::new(
1765 tonic::body::Body::default(),
1766 );
1767 let headers = response.headers_mut();
1768 headers
1769 .insert(
1770 tonic::Status::GRPC_STATUS,
1771 (tonic::Code::Unimplemented as i32).into(),
1772 );
1773 headers
1774 .insert(
1775 http::header::CONTENT_TYPE,
1776 tonic::metadata::GRPC_CONTENT_TYPE,
1777 );
1778 Ok(response)
1779 })
1780 }
1781 }
1782 }
1783 }
1784 impl<T> Clone for SpeechToTextServer<T> {
1785 fn clone(&self) -> Self {
1786 let inner = self.inner.clone();
1787 Self {
1788 inner,
1789 accept_compression_encodings: self.accept_compression_encodings,
1790 send_compression_encodings: self.send_compression_encodings,
1791 max_decoding_message_size: self.max_decoding_message_size,
1792 max_encoding_message_size: self.max_encoding_message_size,
1793 }
1794 }
1795 }
1796 pub const SERVICE_NAME: &str = "rime.SpeechToText";
1798 impl<T> tonic::server::NamedService for SpeechToTextServer<T> {
1799 const NAME: &'static str = SERVICE_NAME;
1800 }
1801}