Adapters API Reference
External integrations: audio recording, OpenAI APIs, clipboard.
Audio Recorder
shh.adapters.audio.recorder
AudioRecorder
Async Context Manager for recording audio from the microphone. Usage: async with AudioRecorder(sample_rate=16000, max_duration=60) as recorder: # Recording in progress await do_something()
Source code in shh/adapters/audio/recorder.py
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 | |
__aenter__()
async
Start the audio recording stream. Returns: Self for use within the async context manager.
Source code in shh/adapters/audio/recorder.py
__aexit__(exc_type, exc_value, traceback)
async
Stop the audio recording stream and finalize the recording.
Source code in shh/adapters/audio/recorder.py
__init__(sample_rate=SAMPLE_RATE, max_duration=None)
Initialize the AudioRecorder.
Source code in shh/adapters/audio/recorder.py
elapsed_time()
Get the elapsed recording time in seconds. Returns: Elapsed time in seconds.
get_audio()
Retrieve the recorded audio data as a single NumPy array. Returns: A NumPy array containing the recorded audio data.
Source code in shh/adapters/audio/recorder.py
is_max_duration_reached()
Audio Processor
shh.adapters.audio.processor
save_audio_to_wav(audio_data, sample_rate=SAMPLE_RATE)
Save audio data to a temporary WAV file. This function is not responsible for cleaning up the temporary file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
audio_data
|
NDArray[float32]
|
The audio data to save. |
required |
sample_rate
|
int
|
The sample rate of the audio data. |
SAMPLE_RATE
|
Returns: Path: The path to the saved WAV file. Raises: AudioProcessingError: If there is an error saving the audio file.
Source code in shh/adapters/audio/processor.py
Whisper Client
shh.adapters.whisper.client
transcribe_audio(audio_file_path, api_key, model='whisper-1')
async
Transcribe audio using OpenAI's Whisper API.
Source code in shh/adapters/whisper/client.py
LLM Formatter
shh.adapters.llm.formatter
FormattedTranscription
format_transcription(text, style=TranscriptionStyle.NEUTRAL, api_key='', target_language=None)
async
Format the transcription text using an AI agent based on the specified style.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
Raw transcription text from Whisper |
required |
style
|
TranscriptionStyle
|
Formatting style to apply (neutral, casual, business) |
NEUTRAL
|
api_key
|
str
|
OpenAI API key for LLM calls |
''
|
target_language
|
str | None
|
Optional language to translate to (e.g., "English", "French", "Spanish") |
None
|
Returns:
| Type | Description |
|---|---|
FormattedTranscription
|
FormattedTranscription with styled and optionally translated text |
Source code in shh/adapters/llm/formatter.py
Clipboard Manager
shh.adapters.clipboard.manager
Clipboard operations for copying transcription results.
copy_to_clipboard(text)
async
Copy text to system clipboard.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
Text to copy to clipboard |
required |
Returns:
| Type | Description |
|---|---|
None
|
None |