.. 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_stream_example.py: Stream of audio from your microphone ==================================== This is an example of using your own Microphone to continuously transcribe what is being uttered. Whenever the recognizer detects a silence in the audio stream from your microphone, it will be transcribed. .. code-block:: default from danspeech import Recognizer from danspeech.pretrained_models import TransferLearned from danspeech.audio.resources import Microphone from danspeech.language_models import DSL3gram # Get a list of microphones found by PyAudio 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)) # Choose the microphone mic_number = input("Pick the number of the microphone you would like to use: ") # Init a microphone object m = Microphone(sampling_rate=16000, device_index=int(mic_number)) # Init a DanSpeech model and create a Recognizer instance model = TransferLearned() recognizer = Recognizer(model=model) # Try using the DSL 3 gram language model try: lm = DSL3gram() recognizer.update_decoder(lm=lm) except ImportError: print("ctcdecode not installed. Using greedy decoding.") print("Speek a lot to adjust silence detection from microphone...") with m as source: recognizer.adjust_for_speech(source, duration=5) # Enable streaming recognizer.enable_streaming() # Create the streaming generator which runs a background thread listening to the microphone stream generator = recognizer.streaming(source=m) # The below code runs for a long time. The generator returns transcriptions of spoken speech from your microphone. print("Speak") for i in range(100000): trans = next(generator) print(trans) .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 0.000 seconds) .. _sphx_glr_download_auto_examples_stream_example.py: .. only :: html .. container:: sphx-glr-footer :class: sphx-glr-footer-example .. container:: sphx-glr-download :download:`Download Python source code: stream_example.py ` .. container:: sphx-glr-download :download:`Download Jupyter notebook: stream_example.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_