-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfastrtc.html
More file actions
2968 lines (2544 loc) · 323 KB
/
Copy pathfastrtc.html
File metadata and controls
2968 lines (2544 loc) · 323 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Python: package fastrtc</title>
</head><body>
<table class="heading">
<tr class="heading-text decor">
<td class="title"> <br><strong class="title">fastrtc</strong></td>
<td class="extra"><a href=".">index</a><br><a href="file:/Users/jason/development/github/voiceagent/examples/python/.venv/lib/python3.12/site-packages/fastrtc/__init__.py">/Users/jason/development/github/voiceagent/examples/python/.venv/lib/python3.12/site-packages/fastrtc/__init__.py</a></td></tr></table>
<p></p>
<p>
<table class="section">
<tr class="decor pkg-content-decor heading-text">
<td class="section-title" colspan=3> <br><strong class="bigsection">Package Contents</strong></td></tr>
<tr><td class="decor pkg-content-decor"><span class="code"> </span></td><td> </td>
<td class="singlecolumn"><table><tr><td class="multicolumn"><a href="fastrtc.credentials.html">credentials</a><br>
<a href="fastrtc.pause_detection.html"><strong>pause_detection</strong> (package)</a><br>
<a href="fastrtc.reply_on_pause.html">reply_on_pause</a><br>
</td><td class="multicolumn"><a href="fastrtc.reply_on_stopwords.html">reply_on_stopwords</a><br>
<a href="fastrtc.speech_to_text.html"><strong>speech_to_text</strong> (package)</a><br>
<a href="fastrtc.stream.html">stream</a><br>
</td><td class="multicolumn"><a href="fastrtc.text_to_speech.html"><strong>text_to_speech</strong> (package)</a><br>
<a href="fastrtc.tracks.html">tracks</a><br>
<a href="fastrtc.utils.html">utils</a><br>
</td><td class="multicolumn"><a href="fastrtc.webrtc.html">webrtc</a><br>
<a href="fastrtc.webrtc_connection_mixin.html">webrtc_connection_mixin</a><br>
<a href="fastrtc.websocket.html">websocket</a><br>
</td></tr></table></td></tr></table><p>
<table class="section">
<tr class="decor index-decor heading-text">
<td class="section-title" colspan=3> <br><strong class="bigsection">Classes</strong></td></tr>
<tr><td class="decor index-decor"><span class="code"> </span></td><td> </td>
<td class="singlecolumn"><dl>
<dt class="heading-text"><a href="builtins.html#Exception">builtins.Exception</a>(<a href="builtins.html#BaseException">builtins.BaseException</a>)
</dt><dd>
<dl>
<dt class="heading-text"><a href="fastrtc.utils.html#WebRTCError">fastrtc.utils.WebRTCError</a>
</dt></dl>
</dd>
<dt class="heading-text"><a href="builtins.html#dict">builtins.dict</a>(<a href="builtins.html#object">builtins.object</a>)
</dt><dd>
<dl>
<dt class="heading-text"><a href="fastrtc.stream.html#UIArgs">fastrtc.stream.UIArgs</a>
</dt></dl>
</dd>
<dt class="heading-text"><a href="builtins.html#object">builtins.object</a>
</dt><dd>
<dl>
<dt class="heading-text"><a href="fastrtc.pause_detection.silero.html#SileroVadOptions">fastrtc.pause_detection.silero.SileroVadOptions</a>
</dt><dt class="heading-text"><a href="fastrtc.reply_on_pause.html#AlgoOptions">fastrtc.reply_on_pause.AlgoOptions</a>
</dt><dt class="heading-text"><a href="fastrtc.tracks.html#VideoStreamHandler">fastrtc.tracks.VideoStreamHandler</a>
</dt><dt class="heading-text"><a href="fastrtc.utils.html#AdditionalOutputs">fastrtc.utils.AdditionalOutputs</a>
</dt><dt class="heading-text"><a href="fastrtc.utils.html#CloseStream">fastrtc.utils.CloseStream</a>
</dt><dt class="heading-text"><a href="typing.html#Any">typing.Any</a>
</dt></dl>
</dd>
<dt class="heading-text"><a href="fastrtc.speech_to_text.stt_.html#STTModel">fastrtc.speech_to_text.stt_.STTModel</a>(<a href="typing.html#Protocol">typing.Protocol</a>)
</dt><dd>
<dl>
<dt class="heading-text"><a href="fastrtc.speech_to_text.stt_.html#MoonshineSTT">fastrtc.speech_to_text.stt_.MoonshineSTT</a>
</dt></dl>
</dd>
<dt class="heading-text"><a href="fastrtc.text_to_speech.tts.html#TTSOptions">fastrtc.text_to_speech.tts.TTSOptions</a>(<a href="builtins.html#object">builtins.object</a>)
</dt><dd>
<dl>
<dt class="heading-text"><a href="fastrtc.text_to_speech.tts.html#CartesiaTTSOptions">fastrtc.text_to_speech.tts.CartesiaTTSOptions</a>
</dt><dt class="heading-text"><a href="fastrtc.text_to_speech.tts.html#KokoroTTSOptions">fastrtc.text_to_speech.tts.KokoroTTSOptions</a>
</dt></dl>
</dd>
<dt class="heading-text"><a href="fastrtc.tracks.html#StreamHandlerBase">fastrtc.tracks.StreamHandlerBase</a>(<a href="abc.html#ABC">abc.ABC</a>)
</dt><dd>
<dl>
<dt class="heading-text"><a href="fastrtc.tracks.html#AsyncStreamHandler">fastrtc.tracks.AsyncStreamHandler</a>
</dt><dd>
<dl>
<dt class="heading-text"><a href="fastrtc.tracks.html#AsyncAudioVideoStreamHandler">fastrtc.tracks.AsyncAudioVideoStreamHandler</a>
</dt></dl>
</dd>
<dt class="heading-text"><a href="fastrtc.tracks.html#StreamHandler">fastrtc.tracks.StreamHandler</a>
</dt><dd>
<dl>
<dt class="heading-text"><a href="fastrtc.reply_on_pause.html#ReplyOnPause">fastrtc.reply_on_pause.ReplyOnPause</a>
</dt><dd>
<dl>
<dt class="heading-text"><a href="fastrtc.reply_on_stopwords.html#ReplyOnStopWords">fastrtc.reply_on_stopwords.ReplyOnStopWords</a>
</dt></dl>
</dd>
<dt class="heading-text"><a href="fastrtc.tracks.html#AudioVideoStreamHandler">fastrtc.tracks.AudioVideoStreamHandler</a>
</dt></dl>
</dd>
</dl>
</dd>
<dt class="heading-text"><a href="fastrtc.webrtc_connection_mixin.html#WebRTCConnectionMixin">fastrtc.webrtc_connection_mixin.WebRTCConnectionMixin</a>(<a href="builtins.html#object">builtins.object</a>)
</dt><dd>
<dl>
<dt class="heading-text"><a href="fastrtc.stream.html#Stream">fastrtc.stream.Stream</a>
</dt><dt class="heading-text"><a href="fastrtc.webrtc.html#WebRTC">fastrtc.webrtc.WebRTC</a>(<a href="gradio.components.base.html#Component">gradio.components.base.Component</a>, <a href="fastrtc.webrtc_connection_mixin.html#WebRTCConnectionMixin">fastrtc.webrtc_connection_mixin.WebRTCConnectionMixin</a>)
</dt></dl>
</dd>
<dt class="heading-text"><a href="gradio.components.base.html#Component">gradio.components.base.Component</a>(<a href="gradio.components.base.html#ComponentBase">gradio.components.base.ComponentBase</a>, <a href="gradio.blocks.html#Block">gradio.blocks.Block</a>)
</dt><dd>
<dl>
<dt class="heading-text"><a href="fastrtc.webrtc.html#WebRTC">fastrtc.webrtc.WebRTC</a>(<a href="gradio.components.base.html#Component">gradio.components.base.Component</a>, <a href="fastrtc.webrtc_connection_mixin.html#WebRTCConnectionMixin">fastrtc.webrtc_connection_mixin.WebRTCConnectionMixin</a>)
</dt></dl>
</dd>
<dt class="heading-text"><a href="gradio.data_classes.html#GradioModel">gradio.data_classes.GradioModel</a>(<a href="gradio.data_classes.html#GradioBaseModel">gradio.data_classes.GradioBaseModel</a>, <a href="pydantic.main.html#BaseModel">pydantic.main.BaseModel</a>)
</dt><dd>
<dl>
<dt class="heading-text"><a href="fastrtc.utils.html#WebRTCData">fastrtc.utils.WebRTCData</a>
</dt></dl>
</dd>
<dt class="heading-text"><a href="typing.html#Protocol">typing.Protocol</a>(<a href="typing.html#Generic">typing.Generic</a>)
</dt><dd>
<dl>
<dt class="heading-text"><a href="fastrtc.pause_detection.protocol.html#PauseDetectionModel">fastrtc.pause_detection.protocol.PauseDetectionModel</a>
</dt></dl>
</dd>
</dl>
<p>
<table class="section">
<tr class="decor title-decor heading-text">
<td class="section-title" colspan=3> <br><a name="AdditionalOutputs">class <strong>AdditionalOutputs</strong></a>(<a href="builtins.html#object">builtins.object</a>)</td></tr>
<tr><td class="decor title-decor" rowspan=2><span class="code"> </span></td>
<td class="decor title-decor" colspan=2><span class="code"><a href="#AdditionalOutputs">AdditionalOutputs</a>(*args) -&gt; None<br>
<br>
<br> </span></td></tr>
<tr><td> </td>
<td class="singlecolumn">Methods defined here:<br>
<dl><dt><a name="AdditionalOutputs-__init__"><strong>__init__</strong></a>(self, *args) -> None</dt><dd><span class="code">Initialize self. See help(type(self)) for accurate signature.</span></dd></dl>
<hr>
Data descriptors defined here:<br>
<dl><dt><strong>__dict__</strong></dt>
<dd><span class="code">dictionary for instance variables</span></dd>
</dl>
<dl><dt><strong>__weakref__</strong></dt>
<dd><span class="code">list of weak references to the object</span></dd>
</dl>
</td></tr></table> <p>
<table class="section">
<tr class="decor title-decor heading-text">
<td class="section-title" colspan=3> <br><a name="AlgoOptions">class <strong>AlgoOptions</strong></a>(<a href="builtins.html#object">builtins.object</a>)</td></tr>
<tr><td class="decor title-decor" rowspan=2><span class="code"> </span></td>
<td class="decor title-decor" colspan=2><span class="code"><a href="#AlgoOptions">AlgoOptions</a>(audio_chunk_duration: float = 0.6, started_talking_threshold: float = 0.2, speech_threshold: float = 0.1, max_continuous_speech_s: float = inf) -&gt; None<br>
<br>
Algorithm options.<br>
<br>
Attributes:<br>
- audio_chunk_duration: Duration in seconds of audio chunks passed to the VAD model.<br>
- started_talking_threshold: If the chunk has more than started_talking_threshold seconds of speech, the user started talking.<br>
- speech_threshold: If, after the user started speaking, there is a chunk with less than speech_threshold seconds of speech, the user stopped speaking.<br>
- max_continuous_speech_s: Max duration of speech chunks before the handler is triggered, even if a pause is not detected by the VAD model.<br> </span></td></tr>
<tr><td> </td>
<td class="singlecolumn">Methods defined here:<br>
<dl><dt><a name="AlgoOptions-__eq__"><strong>__eq__</strong></a>(self, other)</dt><dd><span class="code">Return self==value.</span></dd></dl>
<dl><dt><a name="AlgoOptions-__init__"><strong>__init__</strong></a>(self, audio_chunk_duration: float = 0.6, started_talking_threshold: float = 0.2, speech_threshold: float = 0.1, max_continuous_speech_s: float = inf) -> None</dt><dd><span class="code">Initialize self. See help(type(self)) for accurate signature.</span></dd></dl>
<dl><dt><a name="AlgoOptions-__repr__"><strong>__repr__</strong></a>(self)</dt><dd><span class="code">Return repr(self).</span></dd></dl>
<hr>
Data descriptors defined here:<br>
<dl><dt><strong>__dict__</strong></dt>
<dd><span class="code">dictionary for instance variables</span></dd>
</dl>
<dl><dt><strong>__weakref__</strong></dt>
<dd><span class="code">list of weak references to the object</span></dd>
</dl>
<hr>
Data and other attributes defined here:<br>
<dl><dt><strong>__annotations__</strong> = {'audio_chunk_duration': <class 'float'>, 'max_continuous_speech_s': <class 'float'>, 'speech_threshold': <class 'float'>, 'started_talking_threshold': <class 'float'>}</dl>
<dl><dt><strong>__dataclass_fields__</strong> = {'audio_chunk_duration': Field(name='audio_chunk_duration',type=<class 'f...appingproxy({}),kw_only=False,_field_type=_FIELD), 'max_continuous_speech_s': Field(name='max_continuous_speech_s',type=<class...appingproxy({}),kw_only=False,_field_type=_FIELD), 'speech_threshold': Field(name='speech_threshold',type=<class 'float...appingproxy({}),kw_only=False,_field_type=_FIELD), 'started_talking_threshold': Field(name='started_talking_threshold',type=<cla...appingproxy({}),kw_only=False,_field_type=_FIELD)}</dl>
<dl><dt><strong>__dataclass_params__</strong> = _DataclassParams(init=True,repr=True,eq=True,ord...rue,kw_only=False,slots=False,weakref_slot=False)</dl>
<dl><dt><strong>__hash__</strong> = None</dl>
<dl><dt><strong>__match_args__</strong> = ('audio_chunk_duration', 'started_talking_threshold', 'speech_threshold', 'max_continuous_speech_s')</dl>
<dl><dt><strong>audio_chunk_duration</strong> = 0.6</dl>
<dl><dt><strong>max_continuous_speech_s</strong> = inf</dl>
<dl><dt><strong>speech_threshold</strong> = 0.1</dl>
<dl><dt><strong>started_talking_threshold</strong> = 0.2</dl>
</td></tr></table> <p>
<table class="section">
<tr class="decor title-decor heading-text">
<td class="section-title" colspan=3> <br><a name="AsyncAudioVideoStreamHandler">class <strong>AsyncAudioVideoStreamHandler</strong></a>(<a href="fastrtc.tracks.html#AsyncStreamHandler">AsyncStreamHandler</a>)</td></tr>
<tr><td class="decor title-decor" rowspan=2><span class="code"> </span></td>
<td class="decor title-decor" colspan=2><span class="code"><a href="#AsyncAudioVideoStreamHandler">AsyncAudioVideoStreamHandler</a>(expected_layout: "Literal['mono', 'stereo']" = 'mono', output_sample_rate: 'int' = 24000, output_frame_size: 'int | None' = None, input_sample_rate: 'int' = 48000, fps: 'int' = 30) -&gt; 'None'<br>
<br>
Abstract base class for asynchronous handlers processing both audio and video.<br>
<br>
Inherits from `<a href="#AsyncStreamHandler">AsyncStreamHandler</a>` (asynchronous audio) and adds abstract<br>
coroutines for handling video frames asynchronously. Subclasses must implement<br>
the async audio methods (`receive`, `emit`, `start_up`) and the async video<br>
methods (`video_receive`, `video_emit`), as well as `copy`.<br> </span></td></tr>
<tr><td> </td>
<td class="singlecolumn"><dl><dt>Method resolution order:</dt>
<dd><a href="fastrtc.tracks.html#AsyncAudioVideoStreamHandler">AsyncAudioVideoStreamHandler</a></dd>
<dd><a href="fastrtc.tracks.html#AsyncStreamHandler">AsyncStreamHandler</a></dd>
<dd><a href="fastrtc.tracks.html#StreamHandlerBase">StreamHandlerBase</a></dd>
<dd><a href="abc.html#ABC">abc.ABC</a></dd>
<dd><a href="builtins.html#object">builtins.object</a></dd>
</dl>
<hr>
Methods defined here:<br>
<dl><dt><a name="AsyncAudioVideoStreamHandler-copy"><strong>copy</strong></a>(self) -> 'AsyncAudioVideoStreamHandler'</dt><dd><span class="code">Create a copy of this asynchronous audio-video stream handler instance.<br>
<br>
Returns:<br>
A new instance of the concrete <a href="#AsyncAudioVideoStreamHandler">AsyncAudioVideoStreamHandler</a> subclass.</span></dd></dl>
<dl><dt>async <a name="AsyncAudioVideoStreamHandler-video_emit"><strong>video_emit</strong></a>(self) -> 'VideoEmitType'</dt><dd><span class="code">Produce the next output video frame asynchronously.<br>
<br>
Returns:<br>
An output item conforming to `VideoEmitType`, typically a numpy array<br>
representing the video frame, or None.</span></dd></dl>
<dl><dt>async <a name="AsyncAudioVideoStreamHandler-video_receive"><strong>video_receive</strong></a>(self, frame: 'npt.NDArray[np.float32]') -> 'None'</dt><dd><span class="code">Process an incoming video frame asynchronously.<br>
<br>
Args:<br>
frame: The video frame data as a numpy array (float32).<br>
Note: The type hint differs from the synchronous version.<br>
Consider standardizing if possible.</span></dd></dl>
<hr>
Data and other attributes defined here:<br>
<dl><dt><strong>__abstractmethods__</strong> = frozenset({'copy', 'emit', 'receive', 'video_emit', 'video_receive'})</dl>
<dl><dt><strong>__annotations__</strong> = {}</dl>
<hr>
Methods inherited from <a href="fastrtc.tracks.html#AsyncStreamHandler">AsyncStreamHandler</a>:<br>
<dl><dt>async <a name="AsyncAudioVideoStreamHandler-emit"><strong>emit</strong></a>(self) -> 'EmitType'</dt><dd><span class="code">Produce the next output chunk asynchronously.<br>
<br>
This coroutine is called to generate the output to be sent back over the stream.<br>
<br>
Returns:<br>
An output item conforming to `EmitType`, which could be audio data,<br>
additional outputs, control signals (like `<a href="#CloseStream">CloseStream</a>`), or None.</span></dd></dl>
<dl><dt>async <a name="AsyncAudioVideoStreamHandler-receive"><strong>receive</strong></a>(self, frame: 'tuple[int, npt.NDArray[np.int16]]') -> 'None'</dt><dd><span class="code">Process an incoming audio frame asynchronously.<br>
<br>
Args:<br>
frame: A tuple containing the sample rate (int) and the audio data<br>
as a numpy array (int16).</span></dd></dl>
<dl><dt>async <a name="AsyncAudioVideoStreamHandler-start_up"><strong>start_up</strong></a>(self)</dt><dd><span class="code">Optional asynchronous startup logic. Must be a coroutine (async def).</span></dd></dl>
<hr>
Methods inherited from <a href="fastrtc.tracks.html#StreamHandlerBase">StreamHandlerBase</a>:<br>
<dl><dt><a name="AsyncAudioVideoStreamHandler-__init__"><strong>__init__</strong></a>(self, expected_layout: "Literal['mono', 'stereo']" = 'mono', output_sample_rate: 'int' = 24000, output_frame_size: 'int | None' = None, input_sample_rate: 'int' = 48000, fps: 'int' = 30) -> 'None'</dt><dd><span class="code">Initializes the <a href="fastrtc.tracks.html#StreamHandlerBase">StreamHandlerBase</a>.<br>
<br>
Args:<br>
expected_layout: Expected input audio layout ('mono' or 'stereo').<br>
output_sample_rate: Target output audio sample rate.<br>
output_frame_size: Deprecated. Frame size is now derived from sample rate.<br>
input_sample_rate: Expected input audio sample rate.<br>
fps: The desired frame rate for the output audio.</span></dd></dl>
<dl><dt>async <a name="AsyncAudioVideoStreamHandler-fetch_args"><strong>fetch_args</strong></a>(self)</dt></dl>
<dl><dt><a name="AsyncAudioVideoStreamHandler-resample"><strong>resample</strong></a>(self, frame: 'AudioFrame') -> 'Generator[AudioFrame, None, None]'</dt><dd><span class="code">Resamples an incoming audio frame to the target format and sample rate.<br>
<br>
Initializes the resampler on the first call.<br>
<br>
Args:<br>
frame: The input AudioFrame.<br>
<br>
Yields:<br>
Resampled AudioFrame(s).</span></dd></dl>
<dl><dt><a name="AsyncAudioVideoStreamHandler-reset"><strong>reset</strong></a>(self)</dt><dd><span class="code">Resets the argument set event.</span></dd></dl>
<dl><dt>async <a name="AsyncAudioVideoStreamHandler-send_message"><strong>send_message</strong></a>(self, msg: 'str')</dt><dd><span class="code">Asynchronously sends a message over the data channel.<br>
<br>
Args:<br>
msg: The string message to send.</span></dd></dl>
<dl><dt><a name="AsyncAudioVideoStreamHandler-send_message_sync"><strong>send_message_sync</strong></a>(self, msg: 'str')</dt><dd><span class="code">Synchronously sends a message over the data channel.<br>
<br>
Runs the async `send_message` in the event loop and waits for completion.<br>
<br>
Args:<br>
msg: The string message to send.</span></dd></dl>
<dl><dt><a name="AsyncAudioVideoStreamHandler-set_args"><strong>set_args</strong></a>(self, args: 'list[Any]')</dt><dd><span class="code">Sets additional arguments received (e.g., from UI components).<br>
<br>
Args:<br>
args: A list of arguments.</span></dd></dl>
<dl><dt><a name="AsyncAudioVideoStreamHandler-set_channel"><strong>set_channel</strong></a>(self, channel: 'DataChannel')</dt><dd><span class="code">Sets the data channel for communication and signals readiness.<br>
<br>
Args:<br>
channel: The <a href="#WebRTC">WebRTC</a> DataChannel instance.</span></dd></dl>
<dl><dt><a name="AsyncAudioVideoStreamHandler-shutdown"><strong>shutdown</strong></a>(self)</dt><dd><span class="code">Placeholder for shutdown logic. Subclasses can override.</span></dd></dl>
<dl><dt>async <a name="AsyncAudioVideoStreamHandler-wait_for_args"><strong>wait_for_args</strong></a>(self)</dt></dl>
<dl><dt><a name="AsyncAudioVideoStreamHandler-wait_for_args_sync"><strong>wait_for_args_sync</strong></a>(self)</dt></dl>
<hr>
Readonly properties inherited from <a href="fastrtc.tracks.html#StreamHandlerBase">StreamHandlerBase</a>:<br>
<dl><dt><strong>channel</strong></dt>
</dl>
<dl><dt><strong>clear_queue</strong></dt>
</dl>
<dl><dt><strong>loop</strong></dt>
</dl>
<hr>
Data descriptors inherited from <a href="fastrtc.tracks.html#StreamHandlerBase">StreamHandlerBase</a>:<br>
<dl><dt><strong>__dict__</strong></dt>
<dd><span class="code">dictionary for instance variables</span></dd>
</dl>
<dl><dt><strong>__weakref__</strong></dt>
<dd><span class="code">list of weak references to the object</span></dd>
</dl>
<dl><dt><strong>phone_mode</strong></dt>
</dl>
</td></tr></table> <p>
<table class="section">
<tr class="decor title-decor heading-text">
<td class="section-title" colspan=3> <br><a name="AsyncStreamHandler">class <strong>AsyncStreamHandler</strong></a>(<a href="fastrtc.tracks.html#StreamHandlerBase">StreamHandlerBase</a>)</td></tr>
<tr><td class="decor title-decor" rowspan=2><span class="code"> </span></td>
<td class="decor title-decor" colspan=2><span class="code"><a href="#AsyncStreamHandler">AsyncStreamHandler</a>(expected_layout: "Literal['mono', 'stereo']" = 'mono', output_sample_rate: 'int' = 24000, output_frame_size: 'int | None' = None, input_sample_rate: 'int' = 48000, fps: 'int' = 30) -&gt; 'None'<br>
<br>
Abstract base class for asynchronous stream handlers.<br>
<br>
Inherits from `<a href="fastrtc.tracks.html#StreamHandlerBase">StreamHandlerBase</a>` and defines the core asynchronous interface<br>
for processing audio streams using `async`/`await`. Subclasses must implement<br>
`receive`, `emit`, and `copy`. The `start_up` method must also be a coroutine.<br> </span></td></tr>
<tr><td> </td>
<td class="singlecolumn"><dl><dt>Method resolution order:</dt>
<dd><a href="fastrtc.tracks.html#AsyncStreamHandler">AsyncStreamHandler</a></dd>
<dd><a href="fastrtc.tracks.html#StreamHandlerBase">StreamHandlerBase</a></dd>
<dd><a href="abc.html#ABC">abc.ABC</a></dd>
<dd><a href="builtins.html#object">builtins.object</a></dd>
</dl>
<hr>
Methods defined here:<br>
<dl><dt><a name="AsyncStreamHandler-copy"><strong>copy</strong></a>(self) -> 'AsyncStreamHandler'</dt><dd><span class="code">Create a copy of this asynchronous stream handler instance.<br>
<br>
Used to create a new handler for each connection.<br>
<br>
Returns:<br>
A new instance of the concrete <a href="#AsyncStreamHandler">AsyncStreamHandler</a> subclass.</span></dd></dl>
<dl><dt>async <a name="AsyncStreamHandler-emit"><strong>emit</strong></a>(self) -> 'EmitType'</dt><dd><span class="code">Produce the next output chunk asynchronously.<br>
<br>
This coroutine is called to generate the output to be sent back over the stream.<br>
<br>
Returns:<br>
An output item conforming to `EmitType`, which could be audio data,<br>
additional outputs, control signals (like `<a href="#CloseStream">CloseStream</a>`), or None.</span></dd></dl>
<dl><dt>async <a name="AsyncStreamHandler-receive"><strong>receive</strong></a>(self, frame: 'tuple[int, npt.NDArray[np.int16]]') -> 'None'</dt><dd><span class="code">Process an incoming audio frame asynchronously.<br>
<br>
Args:<br>
frame: A tuple containing the sample rate (int) and the audio data<br>
as a numpy array (int16).</span></dd></dl>
<dl><dt>async <a name="AsyncStreamHandler-start_up"><strong>start_up</strong></a>(self)</dt><dd><span class="code">Optional asynchronous startup logic. Must be a coroutine (async def).</span></dd></dl>
<hr>
Data and other attributes defined here:<br>
<dl><dt><strong>__abstractmethods__</strong> = frozenset({'copy', 'emit', 'receive'})</dl>
<dl><dt><strong>__annotations__</strong> = {}</dl>
<hr>
Methods inherited from <a href="fastrtc.tracks.html#StreamHandlerBase">StreamHandlerBase</a>:<br>
<dl><dt><a name="AsyncStreamHandler-__init__"><strong>__init__</strong></a>(self, expected_layout: "Literal['mono', 'stereo']" = 'mono', output_sample_rate: 'int' = 24000, output_frame_size: 'int | None' = None, input_sample_rate: 'int' = 48000, fps: 'int' = 30) -> 'None'</dt><dd><span class="code">Initializes the <a href="fastrtc.tracks.html#StreamHandlerBase">StreamHandlerBase</a>.<br>
<br>
Args:<br>
expected_layout: Expected input audio layout ('mono' or 'stereo').<br>
output_sample_rate: Target output audio sample rate.<br>
output_frame_size: Deprecated. Frame size is now derived from sample rate.<br>
input_sample_rate: Expected input audio sample rate.<br>
fps: The desired frame rate for the output audio.</span></dd></dl>
<dl><dt>async <a name="AsyncStreamHandler-fetch_args"><strong>fetch_args</strong></a>(self)</dt></dl>
<dl><dt><a name="AsyncStreamHandler-resample"><strong>resample</strong></a>(self, frame: 'AudioFrame') -> 'Generator[AudioFrame, None, None]'</dt><dd><span class="code">Resamples an incoming audio frame to the target format and sample rate.<br>
<br>
Initializes the resampler on the first call.<br>
<br>
Args:<br>
frame: The input AudioFrame.<br>
<br>
Yields:<br>
Resampled AudioFrame(s).</span></dd></dl>
<dl><dt><a name="AsyncStreamHandler-reset"><strong>reset</strong></a>(self)</dt><dd><span class="code">Resets the argument set event.</span></dd></dl>
<dl><dt>async <a name="AsyncStreamHandler-send_message"><strong>send_message</strong></a>(self, msg: 'str')</dt><dd><span class="code">Asynchronously sends a message over the data channel.<br>
<br>
Args:<br>
msg: The string message to send.</span></dd></dl>
<dl><dt><a name="AsyncStreamHandler-send_message_sync"><strong>send_message_sync</strong></a>(self, msg: 'str')</dt><dd><span class="code">Synchronously sends a message over the data channel.<br>
<br>
Runs the async `send_message` in the event loop and waits for completion.<br>
<br>
Args:<br>
msg: The string message to send.</span></dd></dl>
<dl><dt><a name="AsyncStreamHandler-set_args"><strong>set_args</strong></a>(self, args: 'list[Any]')</dt><dd><span class="code">Sets additional arguments received (e.g., from UI components).<br>
<br>
Args:<br>
args: A list of arguments.</span></dd></dl>
<dl><dt><a name="AsyncStreamHandler-set_channel"><strong>set_channel</strong></a>(self, channel: 'DataChannel')</dt><dd><span class="code">Sets the data channel for communication and signals readiness.<br>
<br>
Args:<br>
channel: The <a href="#WebRTC">WebRTC</a> DataChannel instance.</span></dd></dl>
<dl><dt><a name="AsyncStreamHandler-shutdown"><strong>shutdown</strong></a>(self)</dt><dd><span class="code">Placeholder for shutdown logic. Subclasses can override.</span></dd></dl>
<dl><dt>async <a name="AsyncStreamHandler-wait_for_args"><strong>wait_for_args</strong></a>(self)</dt></dl>
<dl><dt><a name="AsyncStreamHandler-wait_for_args_sync"><strong>wait_for_args_sync</strong></a>(self)</dt></dl>
<hr>
Readonly properties inherited from <a href="fastrtc.tracks.html#StreamHandlerBase">StreamHandlerBase</a>:<br>
<dl><dt><strong>channel</strong></dt>
</dl>
<dl><dt><strong>clear_queue</strong></dt>
</dl>
<dl><dt><strong>loop</strong></dt>
</dl>
<hr>
Data descriptors inherited from <a href="fastrtc.tracks.html#StreamHandlerBase">StreamHandlerBase</a>:<br>
<dl><dt><strong>__dict__</strong></dt>
<dd><span class="code">dictionary for instance variables</span></dd>
</dl>
<dl><dt><strong>__weakref__</strong></dt>
<dd><span class="code">list of weak references to the object</span></dd>
</dl>
<dl><dt><strong>phone_mode</strong></dt>
</dl>
</td></tr></table> <p>
<table class="section">
<tr class="decor title-decor heading-text">
<td class="section-title" colspan=3> <br><a name="AudioVideoStreamHandler">class <strong>AudioVideoStreamHandler</strong></a>(<a href="fastrtc.tracks.html#StreamHandler">StreamHandler</a>)</td></tr>
<tr><td class="decor title-decor" rowspan=2><span class="code"> </span></td>
<td class="decor title-decor" colspan=2><span class="code"><a href="#AudioVideoStreamHandler">AudioVideoStreamHandler</a>(expected_layout: "Literal['mono', 'stereo']" = 'mono', output_sample_rate: 'int' = 24000, output_frame_size: 'int | None' = None, input_sample_rate: 'int' = 48000, fps: 'int' = 30) -&gt; 'None'<br>
<br>
Abstract base class for synchronous handlers processing both audio and video.<br>
<br>
Inherits from `<a href="#StreamHandler">StreamHandler</a>` (synchronous audio) and adds abstract methods<br>
for handling video frames synchronously. Subclasses must implement the audio<br>
methods (`receive`, `emit`) and the video methods (`video_receive`, `video_emit`),<br>
as well as `copy`.<br> </span></td></tr>
<tr><td> </td>
<td class="singlecolumn"><dl><dt>Method resolution order:</dt>
<dd><a href="fastrtc.tracks.html#AudioVideoStreamHandler">AudioVideoStreamHandler</a></dd>
<dd><a href="fastrtc.tracks.html#StreamHandler">StreamHandler</a></dd>
<dd><a href="fastrtc.tracks.html#StreamHandlerBase">StreamHandlerBase</a></dd>
<dd><a href="abc.html#ABC">abc.ABC</a></dd>
<dd><a href="builtins.html#object">builtins.object</a></dd>
</dl>
<hr>
Methods defined here:<br>
<dl><dt><a name="AudioVideoStreamHandler-copy"><strong>copy</strong></a>(self) -> 'AudioVideoStreamHandler'</dt><dd><span class="code">Create a copy of this audio-video stream handler instance.<br>
<br>
Returns:<br>
A new instance of the concrete <a href="#AudioVideoStreamHandler">AudioVideoStreamHandler</a> subclass.</span></dd></dl>
<dl><dt><a name="AudioVideoStreamHandler-video_emit"><strong>video_emit</strong></a>(self) -> 'VideoEmitType'</dt><dd><span class="code">Produce the next output video frame synchronously.<br>
<br>
Returns:<br>
An output item conforming to `VideoEmitType`, typically a numpy array<br>
representing the video frame, or None.</span></dd></dl>
<dl><dt><a name="AudioVideoStreamHandler-video_receive"><strong>video_receive</strong></a>(self, frame: 'VideoFrame') -> 'None'</dt><dd><span class="code">Process an incoming video frame synchronously.<br>
<br>
Args:<br>
frame: The incoming aiortc `VideoFrame`.</span></dd></dl>
<hr>
Data and other attributes defined here:<br>
<dl><dt><strong>__abstractmethods__</strong> = frozenset({'copy', 'emit', 'receive', 'video_emit', 'video_receive'})</dl>
<dl><dt><strong>__annotations__</strong> = {}</dl>
<hr>
Methods inherited from <a href="fastrtc.tracks.html#StreamHandler">StreamHandler</a>:<br>
<dl><dt><a name="AudioVideoStreamHandler-emit"><strong>emit</strong></a>(self) -> 'EmitType'</dt><dd><span class="code">Produce the next output chunk synchronously.<br>
<br>
This method is called to generate the output to be sent back over the stream.<br>
<br>
Returns:<br>
An output item conforming to `EmitType`, which could be audio data,<br>
additional outputs, control signals (like `<a href="#CloseStream">CloseStream</a>`), or None.</span></dd></dl>
<dl><dt><a name="AudioVideoStreamHandler-receive"><strong>receive</strong></a>(self, frame: 'tuple[int, npt.NDArray[np.int16]]') -> 'None'</dt><dd><span class="code">Process an incoming audio frame synchronously.<br>
<br>
Args:<br>
frame: A tuple containing the sample rate (int) and the audio data<br>
as a numpy array (int16).</span></dd></dl>
<dl><dt><a name="AudioVideoStreamHandler-start_up"><strong>start_up</strong></a>(self)</dt><dd><span class="code">Optional synchronous startup logic. Can be overridden by subclasses.</span></dd></dl>
<hr>
Methods inherited from <a href="fastrtc.tracks.html#StreamHandlerBase">StreamHandlerBase</a>:<br>
<dl><dt><a name="AudioVideoStreamHandler-__init__"><strong>__init__</strong></a>(self, expected_layout: "Literal['mono', 'stereo']" = 'mono', output_sample_rate: 'int' = 24000, output_frame_size: 'int | None' = None, input_sample_rate: 'int' = 48000, fps: 'int' = 30) -> 'None'</dt><dd><span class="code">Initializes the <a href="fastrtc.tracks.html#StreamHandlerBase">StreamHandlerBase</a>.<br>
<br>
Args:<br>
expected_layout: Expected input audio layout ('mono' or 'stereo').<br>
output_sample_rate: Target output audio sample rate.<br>
output_frame_size: Deprecated. Frame size is now derived from sample rate.<br>
input_sample_rate: Expected input audio sample rate.<br>
fps: The desired frame rate for the output audio.</span></dd></dl>
<dl><dt>async <a name="AudioVideoStreamHandler-fetch_args"><strong>fetch_args</strong></a>(self)</dt></dl>
<dl><dt><a name="AudioVideoStreamHandler-resample"><strong>resample</strong></a>(self, frame: 'AudioFrame') -> 'Generator[AudioFrame, None, None]'</dt><dd><span class="code">Resamples an incoming audio frame to the target format and sample rate.<br>
<br>
Initializes the resampler on the first call.<br>
<br>
Args:<br>
frame: The input AudioFrame.<br>
<br>
Yields:<br>
Resampled AudioFrame(s).</span></dd></dl>
<dl><dt><a name="AudioVideoStreamHandler-reset"><strong>reset</strong></a>(self)</dt><dd><span class="code">Resets the argument set event.</span></dd></dl>
<dl><dt>async <a name="AudioVideoStreamHandler-send_message"><strong>send_message</strong></a>(self, msg: 'str')</dt><dd><span class="code">Asynchronously sends a message over the data channel.<br>
<br>
Args:<br>
msg: The string message to send.</span></dd></dl>
<dl><dt><a name="AudioVideoStreamHandler-send_message_sync"><strong>send_message_sync</strong></a>(self, msg: 'str')</dt><dd><span class="code">Synchronously sends a message over the data channel.<br>
<br>
Runs the async `send_message` in the event loop and waits for completion.<br>
<br>
Args:<br>
msg: The string message to send.</span></dd></dl>
<dl><dt><a name="AudioVideoStreamHandler-set_args"><strong>set_args</strong></a>(self, args: 'list[Any]')</dt><dd><span class="code">Sets additional arguments received (e.g., from UI components).<br>
<br>
Args:<br>
args: A list of arguments.</span></dd></dl>
<dl><dt><a name="AudioVideoStreamHandler-set_channel"><strong>set_channel</strong></a>(self, channel: 'DataChannel')</dt><dd><span class="code">Sets the data channel for communication and signals readiness.<br>
<br>
Args:<br>
channel: The <a href="#WebRTC">WebRTC</a> DataChannel instance.</span></dd></dl>
<dl><dt><a name="AudioVideoStreamHandler-shutdown"><strong>shutdown</strong></a>(self)</dt><dd><span class="code">Placeholder for shutdown logic. Subclasses can override.</span></dd></dl>
<dl><dt>async <a name="AudioVideoStreamHandler-wait_for_args"><strong>wait_for_args</strong></a>(self)</dt></dl>
<dl><dt><a name="AudioVideoStreamHandler-wait_for_args_sync"><strong>wait_for_args_sync</strong></a>(self)</dt></dl>
<hr>
Readonly properties inherited from <a href="fastrtc.tracks.html#StreamHandlerBase">StreamHandlerBase</a>:<br>
<dl><dt><strong>channel</strong></dt>
</dl>
<dl><dt><strong>clear_queue</strong></dt>
</dl>
<dl><dt><strong>loop</strong></dt>
</dl>
<hr>
Data descriptors inherited from <a href="fastrtc.tracks.html#StreamHandlerBase">StreamHandlerBase</a>:<br>
<dl><dt><strong>__dict__</strong></dt>
<dd><span class="code">dictionary for instance variables</span></dd>
</dl>
<dl><dt><strong>__weakref__</strong></dt>
<dd><span class="code">list of weak references to the object</span></dd>
</dl>
<dl><dt><strong>phone_mode</strong></dt>
</dl>
</td></tr></table> <p>
<table class="section">
<tr class="decor title-decor heading-text">
<td class="section-title" colspan=3> <br><a name="CartesiaTTSOptions">class <strong>CartesiaTTSOptions</strong></a>(<a href="fastrtc.text_to_speech.tts.html#TTSOptions">TTSOptions</a>)</td></tr>
<tr><td class="decor title-decor" rowspan=2><span class="code"> </span></td>
<td class="decor title-decor" colspan=2><span class="code"><a href="#CartesiaTTSOptions">CartesiaTTSOptions</a>(voice: str = '71a7ad14-091c-4e8e-a314-022ece01c121', language: str = 'en', emotion: list[str] = &lt;factory&gt;, cartesia_version: str = '2024-06-10', model: str = 'sonic-2', sample_rate: int = 22050) -&gt; None<br>
<br>
<a href="#CartesiaTTSOptions">CartesiaTTSOptions</a>(voice: str = '71a7ad14-091c-4e8e-a314-022ece01c121', language: str = 'en', emotion: list[str] = <factory>, cartesia_version: str = '2024-06-10', model: str = 'sonic-2', sample_rate: int = 22050)<br> </span></td></tr>
<tr><td> </td>
<td class="singlecolumn"><dl><dt>Method resolution order:</dt>
<dd><a href="fastrtc.text_to_speech.tts.html#CartesiaTTSOptions">CartesiaTTSOptions</a></dd>
<dd><a href="fastrtc.text_to_speech.tts.html#TTSOptions">TTSOptions</a></dd>
<dd><a href="builtins.html#object">builtins.object</a></dd>
</dl>
<hr>
Methods defined here:<br>
<dl><dt><a name="CartesiaTTSOptions-__eq__"><strong>__eq__</strong></a>(self, other)</dt><dd><span class="code">Return self==value.</span></dd></dl>
<dl><dt><a name="CartesiaTTSOptions-__init__"><strong>__init__</strong></a>(self, voice: str = '71a7ad14-091c-4e8e-a314-022ece01c121', language: str = 'en', emotion: list[str] = <factory>, cartesia_version: str = '2024-06-10', model: str = 'sonic-2', sample_rate: int = 22050) -> None</dt><dd><span class="code">Initialize self. See help(type(self)) for accurate signature.</span></dd></dl>
<dl><dt><a name="CartesiaTTSOptions-__repr__"><strong>__repr__</strong></a>(self)</dt><dd><span class="code">Return repr(self).</span></dd></dl>
<hr>
Data and other attributes defined here:<br>
<dl><dt><strong>__annotations__</strong> = {'cartesia_version': <class 'str'>, 'emotion': list[str], 'language': <class 'str'>, 'model': <class 'str'>, 'sample_rate': <class 'int'>, 'voice': <class 'str'>}</dl>
<dl><dt><strong>__dataclass_fields__</strong> = {'cartesia_version': Field(name='cartesia_version',type=<class 'str'>...appingproxy({}),kw_only=False,_field_type=_FIELD), 'emotion': Field(name='emotion',type=list[str],default=<dat...appingproxy({}),kw_only=False,_field_type=_FIELD), 'language': Field(name='language',type=<class 'str'>,default...appingproxy({}),kw_only=False,_field_type=_FIELD), 'model': Field(name='model',type=<class 'str'>,default='s...appingproxy({}),kw_only=False,_field_type=_FIELD), 'sample_rate': Field(name='sample_rate',type=<class 'int'>,defa...appingproxy({}),kw_only=False,_field_type=_FIELD), 'voice': Field(name='voice',type=<class 'str'>,default='7...appingproxy({}),kw_only=False,_field_type=_FIELD)}</dl>
<dl><dt><strong>__dataclass_params__</strong> = _DataclassParams(init=True,repr=True,eq=True,ord...rue,kw_only=False,slots=False,weakref_slot=False)</dl>
<dl><dt><strong>__hash__</strong> = None</dl>
<dl><dt><strong>__match_args__</strong> = ('voice', 'language', 'emotion', 'cartesia_version', 'model', 'sample_rate')</dl>
<dl><dt><strong>cartesia_version</strong> = '2024-06-10'</dl>
<dl><dt><strong>language</strong> = 'en'</dl>
<dl><dt><strong>model</strong> = 'sonic-2'</dl>
<dl><dt><strong>sample_rate</strong> = 22050</dl>
<dl><dt><strong>voice</strong> = '71a7ad14-091c-4e8e-a314-022ece01c121'</dl>
<hr>
Data descriptors inherited from <a href="fastrtc.text_to_speech.tts.html#TTSOptions">TTSOptions</a>:<br>
<dl><dt><strong>__dict__</strong></dt>
<dd><span class="code">dictionary for instance variables</span></dd>
</dl>
<dl><dt><strong>__weakref__</strong></dt>
<dd><span class="code">list of weak references to the object</span></dd>
</dl>
</td></tr></table> <p>
<table class="section">
<tr class="decor title-decor heading-text">
<td class="section-title" colspan=3> <br><a name="CloseStream">class <strong>CloseStream</strong></a>(<a href="builtins.html#object">builtins.object</a>)</td></tr>
<tr><td class="decor title-decor" rowspan=2><span class="code"> </span></td>
<td class="decor title-decor" colspan=2><span class="code"><a href="#CloseStream">CloseStream</a>(msg: str = '<a href="#Stream">Stream</a> closed') -&gt; None<br>
<br>
<br> </span></td></tr>
<tr><td> </td>
<td class="singlecolumn">Methods defined here:<br>
<dl><dt><a name="CloseStream-__init__"><strong>__init__</strong></a>(self, msg: str = 'Stream closed') -> None</dt><dd><span class="code">Initialize self. See help(type(self)) for accurate signature.</span></dd></dl>
<hr>
Data descriptors defined here:<br>
<dl><dt><strong>__dict__</strong></dt>
<dd><span class="code">dictionary for instance variables</span></dd>
</dl>
<dl><dt><strong>__weakref__</strong></dt>
<dd><span class="code">list of weak references to the object</span></dd>
</dl>
</td></tr></table> <p>
<table class="section">
<tr class="decor title-decor heading-text">
<td class="section-title" colspan=3> <br><a name="KokoroTTSOptions">class <strong>KokoroTTSOptions</strong></a>(<a href="fastrtc.text_to_speech.tts.html#TTSOptions">TTSOptions</a>)</td></tr>
<tr><td class="decor title-decor" rowspan=2><span class="code"> </span></td>
<td class="decor title-decor" colspan=2><span class="code"><a href="#KokoroTTSOptions">KokoroTTSOptions</a>(voice: str = 'af_heart', speed: float = 1.0, lang: str = 'en-us') -&gt; None<br>
<br>
<a href="#KokoroTTSOptions">KokoroTTSOptions</a>(voice: str = 'af_heart', speed: float = 1.0, lang: str = 'en-us')<br> </span></td></tr>
<tr><td> </td>
<td class="singlecolumn"><dl><dt>Method resolution order:</dt>
<dd><a href="fastrtc.text_to_speech.tts.html#KokoroTTSOptions">KokoroTTSOptions</a></dd>
<dd><a href="fastrtc.text_to_speech.tts.html#TTSOptions">TTSOptions</a></dd>
<dd><a href="builtins.html#object">builtins.object</a></dd>
</dl>
<hr>
Methods defined here:<br>
<dl><dt><a name="KokoroTTSOptions-__eq__"><strong>__eq__</strong></a>(self, other)</dt><dd><span class="code">Return self==value.</span></dd></dl>
<dl><dt><a name="KokoroTTSOptions-__init__"><strong>__init__</strong></a>(self, voice: str = 'af_heart', speed: float = 1.0, lang: str = 'en-us') -> None</dt><dd><span class="code">Initialize self. See help(type(self)) for accurate signature.</span></dd></dl>
<dl><dt><a name="KokoroTTSOptions-__repr__"><strong>__repr__</strong></a>(self)</dt><dd><span class="code">Return repr(self).</span></dd></dl>
<hr>
Data and other attributes defined here:<br>
<dl><dt><strong>__annotations__</strong> = {'lang': <class 'str'>, 'speed': <class 'float'>, 'voice': <class 'str'>}</dl>
<dl><dt><strong>__dataclass_fields__</strong> = {'lang': Field(name='lang',type=<class 'str'>,default='en...appingproxy({}),kw_only=False,_field_type=_FIELD), 'speed': Field(name='speed',type=<class 'float'>,default=...appingproxy({}),kw_only=False,_field_type=_FIELD), 'voice': Field(name='voice',type=<class 'str'>,default='a...appingproxy({}),kw_only=False,_field_type=_FIELD)}</dl>
<dl><dt><strong>__dataclass_params__</strong> = _DataclassParams(init=True,repr=True,eq=True,ord...rue,kw_only=False,slots=False,weakref_slot=False)</dl>
<dl><dt><strong>__hash__</strong> = None</dl>
<dl><dt><strong>__match_args__</strong> = ('voice', 'speed', 'lang')</dl>
<dl><dt><strong>lang</strong> = 'en-us'</dl>
<dl><dt><strong>speed</strong> = 1.0</dl>
<dl><dt><strong>voice</strong> = 'af_heart'</dl>
<hr>
Data descriptors inherited from <a href="fastrtc.text_to_speech.tts.html#TTSOptions">TTSOptions</a>:<br>
<dl><dt><strong>__dict__</strong></dt>
<dd><span class="code">dictionary for instance variables</span></dd>
</dl>
<dl><dt><strong>__weakref__</strong></dt>
<dd><span class="code">list of weak references to the object</span></dd>
</dl>
</td></tr></table> <p>
<table class="section">
<tr class="decor title-decor heading-text">
<td class="section-title" colspan=3> <br><strong>ModelOptions</strong> = <a name="ModelOptions">class Any</a>(<a href="builtins.html#object">builtins.object</a>)</td></tr>
<tr><td class="decor title-decor" rowspan=2><span class="code"> </span></td>
<td class="decor title-decor" colspan=2><span class="code"><a href="#ModelOptions">ModelOptions</a>(*args, **kwargs)<br>
<br>
Special type indicating an unconstrained type.<br>
<br>
- Any is compatible with every type.<br>
- Any assumed to have all methods.<br>
- All values assumed to be instances of Any.<br>
<br>
Note that all the above statements are true from the point of view of<br>
static type checkers. At runtime, Any should not be used with instance<br>
checks.<br> </span></td></tr>
<tr><td> </td>
<td class="singlecolumn">Static methods defined here:<br>
<dl><dt><a name="Any-__new__"><strong>__new__</strong></a>(cls, *args, **kwargs)</dt><dd><span class="code">Create and return a new <a href="builtins.html#object">object</a>. See help(type) for accurate signature.</span></dd></dl>
<hr>
Data descriptors defined here:<br>
<dl><dt><strong>__dict__</strong></dt>
<dd><span class="code">dictionary for instance variables</span></dd>
</dl>
<dl><dt><strong>__weakref__</strong></dt>
<dd><span class="code">list of weak references to the object</span></dd>
</dl>
</td></tr></table> <p>
<table class="section">
<tr class="decor title-decor heading-text">
<td class="section-title" colspan=3> <br><a name="MoonshineSTT">class <strong>MoonshineSTT</strong></a>(<a href="fastrtc.speech_to_text.stt_.html#STTModel">STTModel</a>)</td></tr>
<tr><td class="decor title-decor" rowspan=2><span class="code"> </span></td>
<td class="decor title-decor" colspan=2><span class="code"><a href="#MoonshineSTT">MoonshineSTT</a>(model: Literal['moonshine/base', 'moonshine/tiny'] = 'moonshine/base')<br>
<br>
<br> </span></td></tr>
<tr><td> </td>
<td class="singlecolumn"><dl><dt>Method resolution order:</dt>
<dd><a href="fastrtc.speech_to_text.stt_.html#MoonshineSTT">MoonshineSTT</a></dd>
<dd><a href="fastrtc.speech_to_text.stt_.html#STTModel">STTModel</a></dd>
<dd><a href="typing.html#Protocol">typing.Protocol</a></dd>
<dd><a href="typing.html#Generic">typing.Generic</a></dd>
<dd><a href="builtins.html#object">builtins.object</a></dd>
</dl>
<hr>
Methods defined here:<br>
<dl><dt><a name="MoonshineSTT-__init__"><strong>__init__</strong></a>(self, model: Literal['moonshine/base', 'moonshine/tiny'] = 'moonshine/base')</dt><dd><span class="code">Initialize self. See help(type(self)) for accurate signature.</span></dd></dl>
<dl><dt><a name="MoonshineSTT-stt"><strong>stt</strong></a>(self, audio: tuple[int, numpy.ndarray[tuple[typing.Any, ...], numpy.dtype[numpy.int16 | numpy.float32]]]) -> str</dt></dl>
<hr>
Class methods defined here:<br>
<dl><dt><a name="MoonshineSTT-__subclasshook__"><strong>__subclasshook__</strong></a> = _proto_hook(other)<span class="grey"><span class="heading-text"> from typing</span></span></dt></dl>
<hr>
Data and other attributes defined here:<br>
<dl><dt><strong>__abstractmethods__</strong> = frozenset()</dl>
<dl><dt><strong>__annotations__</strong> = {}</dl>
<dl><dt><strong>__parameters__</strong> = ()</dl>
<hr>
Data descriptors inherited from <a href="fastrtc.speech_to_text.stt_.html#STTModel">STTModel</a>:<br>
<dl><dt><strong>__dict__</strong></dt>
<dd><span class="code">dictionary for instance variables</span></dd>
</dl>
<dl><dt><strong>__weakref__</strong></dt>
<dd><span class="code">list of weak references to the object</span></dd>
</dl>
<hr>
Data and other attributes inherited from <a href="fastrtc.speech_to_text.stt_.html#STTModel">STTModel</a>:<br>
<dl><dt><strong>__protocol_attrs__</strong> = {'stt'}</dl>
<hr>
Class methods inherited from <a href="typing.html#Protocol">typing.Protocol</a>:<br>
<dl><dt><a name="MoonshineSTT-__init_subclass__"><strong>__init_subclass__</strong></a>(*args, **kwargs)</dt><dd><span class="code">Function to initialize subclasses.</span></dd></dl>
<hr>
Class methods inherited from <a href="typing.html#Generic">typing.Generic</a>:<br>
<dl><dt><a name="MoonshineSTT-__class_getitem__"><strong>__class_getitem__</strong></a>(...)</dt><dd><span class="code">Parameterizes a generic class.<br>
<br>
At least, parameterizing a generic class is the *main* thing this<br>
method does. For example, for some generic class `Foo`, this is called<br>
when we do `Foo[int]` - there, with `cls=Foo` and `params=int`.<br>
<br>
However, note that this method is also called when defining generic<br>
classes in the first place with `class Foo[T]: ...`.</span></dd></dl>
</td></tr></table> <p>
<table class="section">
<tr class="decor title-decor heading-text">
<td class="section-title" colspan=3> <br><a name="PauseDetectionModel">class <strong>PauseDetectionModel</strong></a>(<a href="typing.html#Protocol">typing.Protocol</a>)</td></tr>
<tr><td class="decor title-decor" rowspan=2><span class="code"> </span></td>
<td class="decor title-decor" colspan=2><span class="code"><a href="#PauseDetectionModel">PauseDetectionModel</a>(*args, **kwargs)<br>
<br>
<br> </span></td></tr>
<tr><td> </td>
<td class="singlecolumn"><dl><dt>Method resolution order:</dt>
<dd><a href="fastrtc.pause_detection.protocol.html#PauseDetectionModel">PauseDetectionModel</a></dd>
<dd><a href="typing.html#Protocol">typing.Protocol</a></dd>
<dd><a href="typing.html#Generic">typing.Generic</a></dd>
<dd><a href="builtins.html#object">builtins.object</a></dd>
</dl>
<hr>
Methods defined here:<br>
<dl><dt><a name="PauseDetectionModel-__init__"><strong>__init__</strong></a> = _no_init_or_replace_init(self, *args, **kwargs)<span class="grey"><span class="heading-text"> from <a href="typing.html">typing</a></span></span></dt></dl>
<dl><dt><a name="PauseDetectionModel-vad"><strong>vad</strong></a>(self, audio: tuple[int, numpy.ndarray[tuple[typing.Any, ...], numpy.dtype[numpy.int16]] | numpy.ndarray[tuple[typing.Any, ...], numpy.dtype[numpy.float32]]], options: Any) -> tuple[float, list[fastrtc.utils.AudioChunk]]</dt></dl>
<dl><dt><a name="PauseDetectionModel-warmup"><strong>warmup</strong></a>(self) -> None</dt></dl>
<hr>
Class methods defined here:<br>
<dl><dt><a name="PauseDetectionModel-__subclasshook__"><strong>__subclasshook__</strong></a> = _proto_hook(other)<span class="grey"><span class="heading-text"> from typing</span></span></dt></dl>
<hr>
Data descriptors defined here:<br>
<dl><dt><strong>__dict__</strong></dt>
<dd><span class="code">dictionary for instance variables</span></dd>
</dl>
<dl><dt><strong>__weakref__</strong></dt>
<dd><span class="code">list of weak references to the object</span></dd>
</dl>
<hr>
Data and other attributes defined here:<br>
<dl><dt><strong>__abstractmethods__</strong> = frozenset()</dl>
<dl><dt><strong>__annotations__</strong> = {}</dl>
<dl><dt><strong>__parameters__</strong> = ()</dl>
<dl><dt><strong>__protocol_attrs__</strong> = {'vad', 'warmup'}</dl>
<hr>
Class methods inherited from <a href="typing.html#Protocol">typing.Protocol</a>:<br>
<dl><dt><a name="PauseDetectionModel-__init_subclass__"><strong>__init_subclass__</strong></a>(*args, **kwargs)</dt><dd><span class="code">Function to initialize subclasses.</span></dd></dl>
<hr>
Class methods inherited from <a href="typing.html#Generic">typing.Generic</a>:<br>
<dl><dt><a name="PauseDetectionModel-__class_getitem__"><strong>__class_getitem__</strong></a>(...)</dt><dd><span class="code">Parameterizes a generic class.<br>
<br>
At least, parameterizing a generic class is the *main* thing this<br>
method does. For example, for some generic class `Foo`, this is called<br>
when we do `Foo[int]` - there, with `cls=Foo` and `params=int`.<br>
<br>
However, note that this method is also called when defining generic<br>
classes in the first place with `class Foo[T]: ...`.</span></dd></dl>
</td></tr></table> <p>
<table class="section">
<tr class="decor title-decor heading-text">
<td class="section-title" colspan=3> <br><a name="ReplyOnPause">class <strong>ReplyOnPause</strong></a>(<a href="fastrtc.tracks.html#StreamHandler">fastrtc.tracks.StreamHandler</a>)</td></tr>
<tr><td class="decor title-decor" rowspan=2><span class="code"> </span></td>
<td class="decor title-decor" colspan=2><span class="code"><a href="#ReplyOnPause">ReplyOnPause</a>(fn: collections.abc.Callable[[tuple[int, numpy.ndarray[tuple[typing.Any, ...], numpy.dtype[numpy.int16]]], typing.Any], collections.abc.Generator[tuple[int, numpy.ndarray[tuple[typing.Any, ...], numpy.dtype[numpy.int16 | numpy.float32]]] | tuple[int, numpy.ndarray[tuple[typing.Any, ...], numpy.dtype[numpy.int16 | numpy.float32]], typing.Literal['mono', 'stereo']] | fastrtc.utils.<a href="#AdditionalOutputs">AdditionalOutputs</a> | tuple[tuple[int, numpy.ndarray[tuple[typing.Any, ...], numpy.dtype[numpy.int16 | numpy.float32]]], fastrtc.utils.<a href="#AdditionalOutputs">AdditionalOutputs</a>] | fastrtc.utils.<a href="#CloseStream">CloseStream</a> | None, None, None]] | collections.abc.Callable[[tuple[int, numpy.ndarray[tuple[typing.Any, ...], numpy.dtype[numpy.int16]]]], collections.abc.Generator[tuple[int, numpy.ndarray[tuple[typing.Any, ...], numpy.dtype[numpy.int16 | numpy.float32]]] | tuple[int, numpy.ndarray[tuple[typing.Any, ...], numpy.dtype[numpy.int16 | numpy.float32]], typing.Literal['mono', 'stereo']] | fastrtc.utils.<a href="#AdditionalOutputs">AdditionalOutputs</a> | tuple[tuple[int, numpy.ndarray[tuple[typing.Any, ...], numpy.dtype[numpy.int16 | numpy.float32]]], fastrtc.utils.<a href="#AdditionalOutputs">AdditionalOutputs</a>] | fastrtc.utils.<a href="#CloseStream">CloseStream</a> | None, None, None]] | collections.abc.Callable[[tuple[int, numpy.ndarray[tuple[typing.Any, ...], numpy.dtype[numpy.int16]]]], collections.abc.AsyncGenerator[tuple[int, numpy.ndarray[tuple[typing.Any, ...], numpy.dtype[numpy.int16 | numpy.float32]]] | tuple[int, numpy.ndarray[tuple[typing.Any, ...], numpy.dtype[numpy.int16 | numpy.float32]], typing.Literal['mono', 'stereo']] | fastrtc.utils.<a href="#AdditionalOutputs">AdditionalOutputs</a> | tuple[tuple[int, numpy.ndarray[tuple[typing.Any, ...], numpy.dtype[numpy.int16 | numpy.float32]]], fastrtc.utils.<a href="#AdditionalOutputs">AdditionalOutputs</a>] | fastrtc.utils.<a href="#CloseStream">CloseStream</a> | None, None]] | collections.abc.Callable[[tuple[int, numpy.ndarray[tuple[typing.Any, ...], numpy.dtype[numpy.int16]]], typing.Any], collections.abc.AsyncGenerator[tuple[int, numpy.ndarray[tuple[typing.Any, ...], numpy.dtype[numpy.int16 | numpy.float32]]] | tuple[int, numpy.ndarray[tuple[typing.Any, ...], numpy.dtype[numpy.int16 | numpy.float32]], typing.Literal['mono', 'stereo']] | fastrtc.utils.<a href="#AdditionalOutputs">AdditionalOutputs</a> | tuple[tuple[int, numpy.ndarray[tuple[typing.Any, ...], numpy.dtype[numpy.int16 | numpy.float32]]], fastrtc.utils.<a href="#AdditionalOutputs">AdditionalOutputs</a>] | fastrtc.utils.<a href="#CloseStream">CloseStream</a> | None, None]] | collections.abc.Callable[[fastrtc.utils.<a href="#WebRTCData">WebRTCData</a>], collections.abc.Generator[tuple[int, numpy.ndarray[tuple[typing.Any, ...], numpy.dtype[numpy.int16 | numpy.float32]]] | tuple[int, numpy.ndarray[tuple[typing.Any, ...], numpy.dtype[numpy.int16 | numpy.float32]], typing.Literal['mono', 'stereo']] | fastrtc.utils.<a href="#AdditionalOutputs">AdditionalOutputs</a> | tuple[tuple[int, numpy.ndarray[tuple[typing.Any, ...], numpy.dtype[numpy.int16 | numpy.float32]]], fastrtc.utils.<a href="#AdditionalOutputs">AdditionalOutputs</a>] | fastrtc.utils.<a href="#CloseStream">CloseStream</a> | None, None, None]] | collections.abc.Callable[[fastrtc.utils.<a href="#WebRTCData">WebRTCData</a>, typing.Any], collections.abc.AsyncGenerator[tuple[int, numpy.ndarray[tuple[typing.Any, ...], numpy.dtype[numpy.int16 | numpy.float32]]] | tuple[int, numpy.ndarray[tuple[typing.Any, ...], numpy.dtype[numpy.int16 | numpy.float32]], typing.Literal['mono', 'stereo']] | fastrtc.utils.<a href="#AdditionalOutputs">AdditionalOutputs</a> | tuple[tuple[int, numpy.ndarray[tuple[typing.Any, ...], numpy.dtype[numpy.int16 | numpy.float32]]], fastrtc.utils.<a href="#AdditionalOutputs">AdditionalOutputs</a>] | fastrtc.utils.<a href="#CloseStream">CloseStream</a> | None, None]], startup_fn: collections.abc.Callable | None = None, algo_options: fastrtc.reply_on_pause.<a href="#AlgoOptions">AlgoOptions</a> | None = None, model_options: typing.Any | None = None, can_interrupt: bool = True, expected_layout: Literal['mono', 'stereo'] = 'mono', output_sample_rate: int = 24000, output_frame_size: int | None = None, input_sample_rate: int = 48000, model: fastrtc.pause_detection.protocol.<a href="#PauseDetectionModel">PauseDetectionModel</a> | None = None, needs_args: bool = False)<br>
<br>
A stream handler that processes incoming audio, detects pauses,<br>
and triggers a reply function (`fn`) when a pause is detected.<br>
<br>
This handler accumulates audio chunks, uses a Voice Activity Detection (VAD)<br>
model to determine speech segments, and identifies pauses based on configurable<br>
thresholds. Once a pause is detected after speech has started, it calls the<br>
provided generator function `fn` with the accumulated audio.<br>
<br>
It can optionally run a `startup_fn` at the beginning and supports interruption<br>
of the reply function if new audio arrives.<br>
<br>
Attributes:<br>
fn (ReplyFnGenerator): The generator function to call when a pause is detected.<br>
startup_fn (Callable | None): An optional function to run at startup.<br>
algo_options (<a href="#AlgoOptions">AlgoOptions</a>): Configuration for the pause detection algorithm.<br>
model_options (<a href="#ModelOptions">ModelOptions</a> | None): Configuration for the VAD model.<br>
can_interrupt (bool): Whether incoming audio can interrupt the `fn` execution.<br>
expected_layout (Literal["mono", "stereo"]): Expected audio channel layout.<br>
output_sample_rate (int): Sample rate for the output audio from `fn`.<br>
input_sample_rate (int): Expected sample rate of the input audio.<br>
model (<a href="#PauseDetectionModel">PauseDetectionModel</a>): The VAD model instance.<br>
state (AppState): The current state of the pause detection logic.<br>
generator (Generator | AsyncGenerator | None): The active generator instance from `fn`.<br>
event (Event): Threading event used to signal pause detection.<br>
loop (asyncio.AbstractEventLoop): The asyncio event loop.<br> </span></td></tr>
<tr><td> </td>
<td class="singlecolumn"><dl><dt>Method resolution order:</dt>
<dd><a href="fastrtc.reply_on_pause.html#ReplyOnPause">ReplyOnPause</a></dd>
<dd><a href="fastrtc.tracks.html#StreamHandler">fastrtc.tracks.StreamHandler</a></dd>
<dd><a href="fastrtc.tracks.html#StreamHandlerBase">fastrtc.tracks.StreamHandlerBase</a></dd>
<dd><a href="abc.html#ABC">abc.ABC</a></dd>
<dd><a href="builtins.html#object">builtins.object</a></dd>
</dl>
<hr>
Methods defined here:<br>
<dl><dt><a name="ReplyOnPause-__init__"><strong>__init__</strong></a>(self, fn: collections.abc.Callable[[tuple[int, numpy.ndarray[tuple[typing.Any, ...], numpy.dtype[numpy.int16]]], typing.Any], collections.abc.Generator[tuple[int, numpy.ndarray[tuple[typing.Any, ...], numpy.dtype[numpy.int16 | numpy.float32]]] | tuple[int, numpy.ndarray[tuple[typing.Any, ...], numpy.dtype[numpy.int16 | numpy.float32]], typing.Literal['mono', 'stereo']] | fastrtc.utils.AdditionalOutputs | tuple[tuple[int, numpy.ndarray[tuple[typing.Any, ...], numpy.dtype[numpy.int16 | numpy.float32]]], fastrtc.utils.AdditionalOutputs] | fastrtc.utils.CloseStream | None, None, None]] | collections.abc.Callable[[tuple[int, numpy.ndarray[tuple[typing.Any, ...], numpy.dtype[numpy.int16]]]], collections.abc.Generator[tuple[int, numpy.ndarray[tuple[typing.Any, ...], numpy.dtype[numpy.int16 | numpy.float32]]] | tuple[int, numpy.ndarray[tuple[typing.Any, ...], numpy.dtype[numpy.int16 | numpy.float32]], typing.Literal['mono', 'stereo']] | fastrtc.utils.AdditionalOutputs | tuple[tuple[int, numpy.ndarray[tuple[typing.Any, ...], numpy.dtype[numpy.int16 | numpy.float32]]], fastrtc.utils.AdditionalOutputs] | fastrtc.utils.CloseStream | None, None, None]] | collections.abc.Callable[[tuple[int, numpy.ndarray[tuple[typing.Any, ...], numpy.dtype[numpy.int16]]]], collections.abc.AsyncGenerator[tuple[int, numpy.ndarray[tuple[typing.Any, ...], numpy.dtype[numpy.int16 | numpy.float32]]] | tuple[int, numpy.ndarray[tuple[typing.Any, ...], numpy.dtype[numpy.int16 | numpy.float32]], typing.Literal['mono', 'stereo']] | fastrtc.utils.AdditionalOutputs | tuple[tuple[int, numpy.ndarray[tuple[typing.Any, ...], numpy.dtype[numpy.int16 | numpy.float32]]], fastrtc.utils.AdditionalOutputs] | fastrtc.utils.CloseStream | None, None]] | collections.abc.Callable[[tuple[int, numpy.ndarray[tuple[typing.Any, ...], numpy.dtype[numpy.int16]]], typing.Any], collections.abc.AsyncGenerator[tuple[int, numpy.ndarray[tuple[typing.Any, ...], numpy.dtype[numpy.int16 | numpy.float32]]] | tuple[int, numpy.ndarray[tuple[typing.Any, ...], numpy.dtype[numpy.int16 | numpy.float32]], typing.Literal['mono', 'stereo']] | fastrtc.utils.AdditionalOutputs | tuple[tuple[int, numpy.ndarray[tuple[typing.Any, ...], numpy.dtype[numpy.int16 | numpy.float32]]], fastrtc.utils.AdditionalOutputs] | fastrtc.utils.CloseStream | None, None]] | collections.abc.Callable[[fastrtc.utils.WebRTCData], collections.abc.Generator[tuple[int, numpy.ndarray[tuple[typing.Any, ...], numpy.dtype[numpy.int16 | numpy.float32]]] | tuple[int, numpy.ndarray[tuple[typing.Any, ...], numpy.dtype[numpy.int16 | numpy.float32]], typing.Literal['mono', 'stereo']] | fastrtc.utils.AdditionalOutputs | tuple[tuple[int, numpy.ndarray[tuple[typing.Any, ...], numpy.dtype[numpy.int16 | numpy.float32]]], fastrtc.utils.AdditionalOutputs] | fastrtc.utils.CloseStream | None, None, None]] | collections.abc.Callable[[fastrtc.utils.WebRTCData, typing.Any], collections.abc.AsyncGenerator[tuple[int, numpy.ndarray[tuple[typing.Any, ...], numpy.dtype[numpy.int16 | numpy.float32]]] | tuple[int, numpy.ndarray[tuple[typing.Any, ...], numpy.dtype[numpy.int16 | numpy.float32]], typing.Literal['mono', 'stereo']] | fastrtc.utils.AdditionalOutputs | tuple[tuple[int, numpy.ndarray[tuple[typing.Any, ...], numpy.dtype[numpy.int16 | numpy.float32]]], fastrtc.utils.AdditionalOutputs] | fastrtc.utils.CloseStream | None, None]], startup_fn: collections.abc.Callable | None = None, algo_options: fastrtc.reply_on_pause.AlgoOptions | None = None, model_options: typing.Any | None = None, can_interrupt: bool = True, expected_layout: Literal['mono', 'stereo'] = 'mono', output_sample_rate: int = 24000, output_frame_size: int | None = None, input_sample_rate: int = 48000, model: fastrtc.pause_detection.protocol.PauseDetectionModel | None = None, needs_args: bool = False)</dt><dd><span class="code">Initializes the <a href="#ReplyOnPause">ReplyOnPause</a> handler.<br>
<br>
Args:<br>
fn: The generator function to execute upon pause detection.<br>
It receives `(sample_rate, audio_array)` and optionally `*args`.<br>
startup_fn: An optional function to run once at the beginning.<br>
algo_options: Options for the pause detection algorithm.<br>
model_options: Options for the VAD model.<br>
can_interrupt: If True, incoming audio during `fn` execution<br>
will stop the generator and process the new audio.<br>
expected_layout: Expected input audio layout ('mono' or 'stereo').<br>
output_sample_rate: The sample rate expected for audio yielded by `fn`.<br>
output_frame_size: Deprecated.<br>
input_sample_rate: The expected sample rate of incoming audio.<br>
model: An optional pre-initialized VAD model instance.<br>
needs_args: Whether the reply function expects additional arguments.</span></dd></dl>
<dl><dt>async <a name="ReplyOnPause-async_iterate"><strong>async_iterate</strong></a>(self, generator) -> tuple[int, numpy.ndarray[tuple[typing.Any, ...], numpy.dtype[numpy.int16 | numpy.float32]]] | tuple[int, numpy.ndarray[tuple[typing.Any, ...], numpy.dtype[numpy.int16 | numpy.float32]], typing.Literal['mono', 'stereo']] | fastrtc.utils.AdditionalOutputs | tuple[tuple[int, numpy.ndarray[tuple[typing.Any, ...], numpy.dtype[numpy.int16 | numpy.float32]]], fastrtc.utils.AdditionalOutputs] | fastrtc.utils.CloseStream | None</dt><dd><span class="code">Helper function to get the next item from an async generator.</span></dd></dl>
<dl><dt><a name="ReplyOnPause-copy"><strong>copy</strong></a>(self)</dt><dd><span class="code">Creates a new instance of <a href="#ReplyOnPause">ReplyOnPause</a> with the same configuration.</span></dd></dl>
<dl><dt><a name="ReplyOnPause-determine_pause"><strong>determine_pause</strong></a>(self, audio: numpy.ndarray, sampling_rate: int, state: fastrtc.reply_on_pause.AppState) -> bool</dt><dd><span class="code">Analyzes an audio chunk to detect if a significant pause occurred after speech.<br>
<br>
Uses the VAD model to measure speech duration within the chunk. Updates the<br>
application state (`state`) regarding whether talking has started and<br>
accumulates speech segments.<br>
<br>
Args:<br>
audio: The numpy array containing the audio chunk.<br>
sampling_rate: The sample rate of the audio chunk.<br>
state: The current application state.<br>
<br>
Returns:<br>
True if a pause satisfying the configured thresholds is detected<br>
after speech has started, False otherwise.</span></dd></dl>
<dl><dt><a name="ReplyOnPause-emit"><strong>emit</strong></a>(self)</dt><dd><span class="code">Produces the next output chunk from the reply generator (`fn`).<br>
<br>
This method is called repeatedly after a pause is detected (event is set).<br>
If the generator is not already running, it initializes it by calling `fn`<br>
with the accumulated audio and any required additional arguments.<br>
It then yields the next item from the generator. Handles both sync and<br>
async generators. Resets the state upon generator completion or error.<br>
<br>
Returns:<br>
The next output item from the generator, or None if no pause event<br>
has occurred or the generator is exhausted.<br>
<br>
Raises:<br>
<a href="builtins.html#Exception">Exception</a>: Re-raises exceptions occurring within the `fn` generator.</span></dd></dl>
<dl><dt><a name="ReplyOnPause-process_audio"><strong>process_audio</strong></a>(self, audio: tuple[int, numpy.ndarray], state: fastrtc.reply_on_pause.AppState) -> None</dt><dd><span class="code">Processes an incoming audio frame.<br>
<br>
Appends the frame to the buffer, runs pause detection on the buffer,<br>
and updates the application state.<br>
<br>
Args:<br>
audio: A tuple containing the sample rate and the audio frame data.<br>
state: The current application state to update.</span></dd></dl>
<dl><dt><a name="ReplyOnPause-receive"><strong>receive</strong></a>(self, frame: tuple[int, numpy.ndarray]) -> None</dt><dd><span class="code">Receives an audio frame from the stream.<br>
<br>
Processes the audio frame using `process_audio`. If a pause is detected,<br>
it sets the `event`. If interruption is enabled and a reply is ongoing,<br>
it closes the current generator and clears the processing queue.<br>
<br>
Args:<br>
frame: A tuple containing the sample rate and the audio frame data.</span></dd></dl>
<dl><dt><a name="ReplyOnPause-reset"><strong>reset</strong></a>(self)</dt><dd><span class="code">Resets the handler state to its initial condition.<br>
<br>
Clears accumulated audio, resets state flags, closes any active generator,<br>
and clears the event flag. Also handles resetting argument state for phone mode.</span></dd></dl>
<dl><dt><a name="ReplyOnPause-start_up"><strong>start_up</strong></a>(self)</dt><dd><span class="code">Executes the startup function `startup_fn` if provided.<br>
<br>
Waits for additional arguments if `_needs_additional_inputs` is True<br>
before calling `startup_fn`. Sets the `event` after completion.</span></dd></dl>
<dl><dt><a name="ReplyOnPause-trigger_response"><strong>trigger_response</strong></a>(self)</dt><dd><span class="code">Manually triggers the response generation process.<br>
<br>
Sets the event flag, effectively simulating a pause detection.<br>
Initializes the stream buffer if it's empty.</span></dd></dl>
<hr>
Data and other attributes defined here:<br>
<dl><dt><strong>__abstractmethods__</strong> = frozenset()</dl>
<dl><dt><strong>__annotations__</strong> = {}</dl>
<hr>
Methods inherited from <a href="fastrtc.tracks.html#StreamHandlerBase">fastrtc.tracks.StreamHandlerBase</a>:<br>
<dl><dt>async <a name="ReplyOnPause-fetch_args"><strong>fetch_args</strong></a>(self)</dt></dl>