know.examples.keyboard_and_audio

Keyboard and audio acquisition

know.examples.keyboard_and_audio.default_keyboard_event_callback(keyboard_data)[source]

Prints some data extracted from keyboard_data :param keyboard_data: Input character

know.examples.keyboard_and_audio.keyboard_and_audio(input_device_index=None, rate=44100, width=2, channels=1, frames_per_buffer=44100, seconds_to_keep_in_stream_buffer=60, audio_data_callback: Callable[[NewType.<locals>.new_type], Any] = <function default_audio_callback>, keyboard_data_callback: Callable[[NewType.<locals>.new_type], Any] = <function default_keyboard_event_callback>)[source]

Starts two independent streams: one for audio and another for keyboard inputs. Prints stream type, timestamp, and additional info about data: Shows input key pressed for keyboard and byte count for audio

Press Esc key to quit.

Parameters
  • input_device_index – find index with PyAudioSourceReader.list_device_info()

  • rate – audio sample rate

  • width – audio byte width

  • channels – number of audio input channels

  • frames_per_buffer – audio samples per buffer

  • seconds_to_keep_in_stream_buffer – max size of audio buffer before data falls off

Returns

None

know.examples.keyboard_and_audio.keyboard_data_signals_an_interrupt(keyboard_data, stop_signal_chars=frozenset({'\x03', '\x04', '\x1b'}))[source]

The function returns a positive stop signal (1) if the character is in the stop_signal_chars set. By default, the stop_signal_chars contains:

  • : (ascii 3 - End of Text)

  • : (ascii 4 - End of Trans)

  • : (ascii 27 - Escape)

(See https://theasciicode.com.ar/ for ascii codes.)

  1. in the form of a string specifying what the ascii code of the input character was

Parameters
  • keyboard_data – Input character

  • stop_signal_chars – Set of stop characters

Returns