@@ -18,14 +18,23 @@ With a single API call, get access to AI models built on the latest AI breakthro
1818
1919# Overview
2020
21+ - [ AssemblyAI's Python SDK] ( #assemblyais-python-sdk )
22+ - [ Overview] ( #overview )
2123- [ Documentation] ( #documentation )
22- - [ Installation] ( #installation )
23- - [ Example] ( #examples )
24- - [ Core Examples] ( #core-examples )
25- - [ LeMUR Examples] ( #lemur-examples )
26- - [ Audio Intelligence Examples] ( #audio-intelligence-examples )
27- - [ Playgrounds] ( #playgrounds )
28- - [ Advanced] ( #advanced-todo )
24+ - [ Quick Start] ( #quick-start )
25+ - [ Installation] ( #installation )
26+ - [ Examples] ( #examples )
27+ - [ ** Core Examples** ] ( #core-examples )
28+ - [ ** LeMUR Examples** ] ( #lemur-examples )
29+ - [ ** Audio Intelligence Examples** ] ( #audio-intelligence-examples )
30+ - [ ** Real-Time Examples** ] ( #real-time-examples )
31+ - [ Playgrounds] ( #playgrounds )
32+ - [ Advanced] ( #advanced )
33+ - [ How the SDK handles Default Configurations] ( #how-the-sdk-handles-default-configurations )
34+ - [ Defining Defaults] ( #defining-defaults )
35+ - [ Overriding Defaults] ( #overriding-defaults )
36+ - [ Synchronous vs Asynchronous] ( #synchronous-vs-asynchronous )
37+ - [ Polling Intervals] ( #polling-intervals )
2938
3039# Documentation
3140
@@ -470,6 +479,113 @@ for result in transcript.auto_highlights.results:
470479
471480---
472481
482+ ### ** Real-Time Examples**
483+
484+ [ Read more about our Real-Time service.] ( https://www.assemblyai.com/docs/Guides/real-time_streaming_transcription )
485+
486+ <details >
487+ <summary >Stream your Microphone in Real-Time</summary >
488+
489+ ``` python
490+ import assemblyai as aai
491+
492+ def on_open (session_opened : aai.RealtimeSessionOpened):
493+ " This function is called when the connection has been established."
494+
495+ print (" Session ID:" , session_opened.session_id)
496+
497+ def on_data (transcript : aai.RealtimeTranscript):
498+ " This function is called when a new transcript has been received."
499+
500+ if not transcript.text:
501+ return
502+
503+ if isinstance (transcript, aai.RealtimeFinalTranscript):
504+ print (transcript.text, end = " \r\n " )
505+ else :
506+ print (transcript.text, end = " \r " )
507+
508+ def on_error (error : aai.RealtimeError):
509+ " This function is called when the connection has been closed."
510+
511+ print (" An error occured:" , error)
512+
513+ def on_close ():
514+ " This function is called when the connection has been closed."
515+
516+ print (" Closing Session" )
517+
518+
519+ # Create the Real-Time transcriber
520+ transcriber = aai.RealtimeTranscriber(
521+ on_data = on_data,
522+ on_error = on_error,
523+ sample_rate = 44_100 ,
524+ on_open = on_open, # optional
525+ on_close = on_close, # optional
526+ )
527+
528+
529+ # Open a microphone stream
530+ microphone_stream = aai.extras.MicrophoneStream()
531+
532+ # Press CTRL+C to abort
533+ transcriber.stream(microphone_stream)
534+
535+ transcriber.close()
536+ ```
537+
538+ </details >
539+
540+ <details >
541+ <summary >Transcribe a Local Audio File in Real-Time</summary >
542+
543+ ``` python
544+ import assemblyai as aai
545+
546+
547+ def on_data (transcript : aai.RealtimeTranscript):
548+ " This function is called when a new transcript has been received."
549+
550+ if not transcript.text:
551+ return
552+
553+ if isinstance (transcript, aai.RealtimeFinalTranscript):
554+ print (transcript.text, end = " \r\n " )
555+ else :
556+ print (transcript.text, end = " \r " )
557+
558+ def on_error (error : aai.RealtimeError):
559+ " This function is called when the connection has been closed."
560+
561+ print (" An error occured:" , error)
562+
563+
564+ # Create the Real-Time transcriber
565+ transcriber = aai.RealtimeTranscriber(
566+ on_data = on_data,
567+ on_error = on_error,
568+ sample_rate = 44_100 ,
569+ on_open = on_open, # optional
570+ on_close = on_close, # optional
571+ )
572+
573+
574+ # Only WAV/PCM16 single channel supported for now
575+ file_stream = aai.extras.stream_file(
576+ filepath = " audio.wav" ,
577+ sample_rate = 44_100 ,
578+ )
579+
580+ transcriber.stream(file_stream)
581+
582+ transcriber.close()
583+ ```
584+
585+ </details >
586+
587+ ---
588+
473589## Playgrounds
474590
475591Visit one of our Playgrounds:
0 commit comments