.. note:: :class: sphx-glr-download-link-note Click :ref:`here ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_real_time_streaming_example.py: Real-time stream of audio from your microphone ============================================== This is an example of using your own Microphone to continuously transcribe what is being uttered, **while it is being uttered**. Whenever the recognizer detects a silence in the audio stream from your microphone, the generator will return is_last=True, and the full transcription from the secondary model. .. code-block:: default from danspeech import Recognizer from danspeech.pretrained_models import CPUStreamingRNN, TestModel from danspeech.audio.resources import Microphone from danspeech.language_models import DSL3gram print("Loading model...") model = CPUStreamingRNN() mic_list = Microphone.list_microphone_names() mic_list_with_numbers = list(zip(range(len(mic_list)), mic_list)) print("Available microphones: {0}".format(mic_list_with_numbers)) mic_number = input("Pick the number of the microphone you would like to use: ") m = Microphone(sampling_rate=16000, device_index=int(mic_number)) r = Recognizer() print("Adjusting energy level...") with m as source: r.adjust_for_ambient_noise(source, duration=1) seconday_model = TestModel() r = Recognizer(model=model) try: lm = DSL3gram() r.update_decoder(lm=lm) except ImportError: print("ctcdecode not installed. Using greedy decoding.") r.enable_real_time_streaming(streaming_model=model, string_parts=False, secondary_model=seconday_model) generator = r.real_time_streaming(source=m) iterating_transcript = "" print("Speak!") while True: is_last, trans = next(generator) # If the transcription is empty, it means that the energy level required for data # was passed, but nothing was predicted. if is_last and trans: print("Final: " + trans) iterating_transcript = "" continue if trans: iterating_transcript += trans print(iterating_transcript) continue .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 0.000 seconds) .. _sphx_glr_download_auto_examples_real_time_streaming_example.py: .. only :: html .. container:: sphx-glr-footer :class: sphx-glr-footer-example .. container:: sphx-glr-download :download:`Download Python source code: real_time_streaming_example.py ` .. container:: sphx-glr-download :download:`Download Jupyter notebook: real_time_streaming_example.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_