Data
Utilities for ingesting and working with local data.
load
extension_map = {'PNG': 'images', 'JPG': 'images', 'JPEG': 'images', 'GIF': 'images', 'SVG': 'images', 'WEBP': 'images', 'BMP': 'images', 'TIFF': 'images', 'MP4': 'videos', 'AVI': 'videos', 'MOV': 'videos', 'WMV': 'videos', 'MPG': 'videos', 'MPEG': 'videos', 'WEBM': 'videos', 'MKV': 'videos', 'DOCX': 'documents', 'PPTX': 'documents', 'PDF': 'documents', 'XLSX': 'documents', 'TXT': 'documents', 'CSV': 'documents', 'MD': 'documents', 'HTML': 'documents', 'HTM': 'documents', 'MP3': 'audio', 'WAV': 'audio', 'M4A': 'audio', 'AAC': 'audio', 'FLAC': 'audio', 'OGG': 'audio', 'ZIP': 'archives', 'RAR': 'archives', '7Z': 'archives', 'TAR': 'archives', 'GZ': 'archives'}
module-attribute
_chunk_text(full_content, chunk_size)
Split long content into reasonably sized chunks for model input.
Source code in npcpy/data/load.py
_extract_audio_from_video(file_path, max_duration=600)
Use ffmpeg to dump the audio track from a video into a temp wav for transcription. Returns the temp path or None.
Source code in npcpy/data/load.py
_transcribe_audio(file_path, language=None)
Best-effort audio transcription using optional dependencies. Tries faster-whisper, then openai/whisper. Falls back to metadata only.
Source code in npcpy/data/load.py
load_audio(file_path, language=None)
Load and transcribe an audio file into text.
Source code in npcpy/data/load.py
load_csv(file_path)
load_docx(file_path)
load_excel(file_path)
load_file_contents(file_path, chunk_size=None)
Source code in npcpy/data/load.py
load_html(file_path)
Source code in npcpy/data/load.py
load_image(file_path)
load_json(file_path)
load_pdf(file_path)
load_pptx(file_path)
Source code in npcpy/data/load.py
load_txt(file_path)
load_video(file_path, language=None, max_audio_seconds=600)
Summarize a video by reporting metadata and (optionally) transcribing its audio track.
Source code in npcpy/data/load.py
audio
CHANNELS = 1
module-attribute
CHUNK = 512
module-attribute
FORMAT = pyaudio.paInt16
module-attribute
RATE = 16000
module-attribute
logger = logging.getLogger(__name__)
module-attribute
audio_callback(in_data, frame_count, time_info, status)
check_ffmpeg()
convert_mp3_to_wav(mp3_file, wav_file)
Source code in npcpy/data/audio.py
create_and_queue_audio(text, state, engine='kokoro', voice=None)
Create and play TTS audio using the unified engine interface.
| Parameters: |
|
|---|
Source code in npcpy/data/audio.py
get_available_stt_engines()
Get info about available STT engines.
Source code in npcpy/data/audio.py
play_audio(filename, state)
Play a WAV file via pyaudio with state awareness.
Source code in npcpy/data/audio.py
process_text_for_tts(text)
Clean text for TTS consumption.
Source code in npcpy/data/audio.py
run_transcription(audio_np)
Source code in npcpy/data/audio.py
speech_to_text(audio_data, engine='whisper', language=None, **kwargs)
Unified STT interface.
| Parameters: |
|
|---|
| Returns: |
|
|---|
Source code in npcpy/data/audio.py
stt_elevenlabs(audio_data, api_key=None, model_id='scribe_v1', language=None)
Transcribe audio using ElevenLabs Scribe API.
| Parameters: |
|
|---|
| Returns: |
|
|---|
Source code in npcpy/data/audio.py
stt_gemini(audio_data, api_key=None, model='gemini-1.5-flash', language=None, mime_type='audio/wav')
Transcribe audio using Gemini API.
| Parameters: |
|
|---|
| Returns: |
|
|---|
Source code in npcpy/data/audio.py
stt_groq(audio_data, api_key=None, model='whisper-large-v3', language=None)
Transcribe audio using Groq's Whisper API (very fast).
| Parameters: |
|
|---|
| Returns: |
|
|---|
Source code in npcpy/data/audio.py
stt_openai(audio_data, api_key=None, model='whisper-1', language=None, response_format='verbose_json', filename='audio.wav')
Transcribe audio using OpenAI Whisper API.
| Parameters: |
|
|---|
| Returns: |
|
|---|
Source code in npcpy/data/audio.py
stt_whisper(audio_data, model_size='base', language=None, device='auto')
Transcribe audio using local Whisper (faster-whisper).
| Parameters: |
|
|---|
| Returns: |
|
|---|
Source code in npcpy/data/audio.py
transcribe_audio_file(file_path, language=None)
File-based transcription helper that prefers the local faster-whisper/whisper setup used elsewhere in this module.
Source code in npcpy/data/audio.py
image
_windows_snip_to_file(file_path)
Helper function to trigger Windows snipping and save to file.
Source code in npcpy/data/image.py
capture_screenshot(full=False)
Function Description
This function captures a screenshot of the current screen and saves it to a file.
Args: npc: The NPC object representing the current NPC. full: Boolean to determine if full screen capture is needed. Default to true. path: Optional path to save the screenshot. Must not use placeholders. Relative paths preferred if the user specifies they want a specific path, otherwise default to None. Returns: A dictionary containing the filename, file path, and model kwargs.
Source code in npcpy/data/image.py
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 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 | |
compress_image(image_bytes, max_size=(800, 600))
Source code in npcpy/data/image.py
text
load_all_files(directory, extensions=None, depth=1)
Function Description
This function loads all text files in a directory and its subdirectories.
Args: directory: The directory to search. Keyword Args: extensions: A list of file extensions to include. depth: The depth of subdirectories to search. Returns: A dictionary with file paths as keys and file contents as values.
Source code in npcpy/data/text.py
rag_search(query, text_data, embedding_model=None, text_data_embedded=None, similarity_threshold=0.3, device='cpu')
Function Description
This function retrieves lines from documents that are relevant to the query.
Args: query: The query string. text_data: A dictionary with file paths as keys and file contents as values. embedding_model: The sentence embedding model. Keyword Args: text_data_embedded: A dictionary with file paths as keys and embedded file contents as values. similarity_threshold: The similarity threshold for considering a line relevant. Returns: A list of relevant snippets.
Source code in npcpy/data/text.py
video
process_video(file_path, table_name)
Source code in npcpy/data/video.py
summarize_video_file(file_path, language=None, max_audio_seconds=600)
Summarize a video using lightweight metadata plus optional audio transcript. Prefers the audio transcription helper in npcpy.data.audio when available.
Source code in npcpy/data/video.py
web
search_brave(query, num_results=5, api_key=None)
Search using Brave Search API.
Source code in npcpy/data/web.py
search_exa(query, api_key=None, top_k=5, search_type='auto', **kwargs)
Search using Exa - the fastest and most accurate web search API for AI.
Source code in npcpy/data/web.py
search_perplexity(query, api_key=None, model='sonar', max_tokens=400, temperature=0.2, top_p=0.9)
Source code in npcpy/data/web.py
search_searxng(query, num_results=5, instance_url=None)
Search using SearXNG public instances.
Source code in npcpy/data/web.py
search_startpage(query, num_results=5)
Search using Startpage (scraping).
Source code in npcpy/data/web.py
search_web(query, num_results=5, provider=None, api_key=None, perplexity_kwargs=None)
Function Description
This function searches the web for information based on a query.
Args: query: The search query. Keyword Args: num_results: The number of search results to retrieve. provider: The search engine provider to use ('perplexity' or 'duckduckgo'). Returns: A list of dictionaries with 'title', 'link', and 'content' keys.
Source code in npcpy/data/web.py
185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 | |