### Install Xcode Command Line Tools Source: https://github.com/n-wn/mac_internal_audio_recording/blob/main/README.md If Swift compilation fails, ensure Xcode Command Line Tools are installed by running this command in the terminal. ```bash xcode-select --install ``` -------------------------------- ### Run Performance Tests Source: https://context7.com/n-wn/mac_internal_audio_recording/llms.txt Install the psutil library and run the performance test script from the project root. ```bash pip install psutil python tests/performance_test.py ``` -------------------------------- ### Run Main Recording Script Source: https://github.com/n-wn/mac_internal_audio_recording/blob/main/README.md Execute the main Python script to start the audio recording tool. Ensure you have granted microphone permissions if needed. ```bash python my_screen_capture_kit.py ``` -------------------------------- ### Low-level Swift Recorder CLI Examples Source: https://context7.com/n-wn/mac_internal_audio_recording/llms.txt Direct command-line invocations of the compiled 'recorder' binary for capturing system audio, microphone, or both. Handles graceful SIGINT for continuous recordings. ```bash # Record internal audio for 15 seconds ./recorder output/system_audio.wav 15 internal # Output: "Recording complete. Audio saved to output/system_audio.wav" # Record microphone only for 30 seconds ./recorder output/mic_audio.wav 30 microphone # Output: "Recording complete. Audio saved to output/mic_audio.wav" # Record both simultaneously for 60 seconds ./recorder output/session.wav 60 both # Output: # "Recording complete. System audio saved to output/session.wav" # "Microphone audio saved to output/session_mic.wav" # Continuous recording interrupted with Ctrl+C ./recorder output/stream.wav 86400 internal # (press Ctrl+C) # Output: "Received interrupt signal, stopping recording..." # "Recording complete. Audio saved to output/stream.wav" ``` -------------------------------- ### run_recording(output_file, duration, recording_type) Source: https://context7.com/n-wn/mac_internal_audio_recording/llms.txt Starts the Swift recorder subprocess to capture audio. It can record internal audio, microphone, or both for a specified duration or continuously. ```APIDOC ## run_recording(output_file, duration, recording_type) ### Description Starts the Swift recorder subprocess to capture audio. It can record internal audio, microphone, or both for a specified duration or continuously. ### Parameters - **output_file** (string) - Required - The path where the audio file will be saved. - **duration** (string) - Required - The duration of the recording in seconds, or 'continuous' for indefinite recording. - **recording_type** (string) - Required - The type of audio to record. Valid values are 'internal', 'microphone', or 'both'. ### Request Example ```python import my_screen_capture_kit as audio_kit output = audio_kit.generate_output_filename() # Record internal audio for 10 seconds audio_kit.run_recording(output, "10", "internal") # Record microphone continuously until Ctrl+C try: audio_kit.run_recording(output, "continuous", "microphone") except KeyboardInterrupt: pass # Record both simultaneously for 30 seconds audio_kit.run_recording(output, "30", "both") ``` ``` -------------------------------- ### Start Swift Recorder Subprocess with Python Source: https://context7.com/n-wn/mac_internal_audio_recording/llms.txt Invokes the Swift recorder as a subprocess with real-time I/O passthrough. Handles continuous recording and numeric durations, supporting 'internal', 'microphone', and 'both' recording types. ```python import my_screen_capture_kit as audio_kit import os # Prerequisites: source verified and binary compiled audio_kit.verify_swift_source() audio_kit.ensure_executable() output = audio_kit.generate_output_filename() # Record internal audio for 10 seconds audio_kit.run_recording(output, "10", "internal") # Swift prints: "Recording complete. Audio saved to output/recording_20240615_143022.wav" # Record microphone continuously until Ctrl+C try: audio_kit.run_recording(output, "continuous", "microphone") except KeyboardInterrupt: pass # Swift prints: "Recording stopped by user." # Record both simultaneously for 30 seconds audio_kit.run_recording(output, "30", "both") # Swift prints: # "Recording complete. System audio saved to output/recording_20240615_143022.wav" # "Microphone audio saved to output/recording_20240615_143022_mic.wav" ``` -------------------------------- ### Timed Microphone Recording Source: https://github.com/n-wn/mac_internal_audio_recording/blob/main/README.md Starts recording microphone audio for a specified duration in seconds. The recording stops automatically after the duration elapses. ```bash Choice: 2 Press Enter for continuous recording, or enter duration in seconds: 30 Recording microphone. Press Ctrl+C to stop and save. # Records for 30 seconds automatically ``` -------------------------------- ### Clone Repository and Navigate Source: https://github.com/n-wn/mac_internal_audio_recording/blob/main/README.md Use these commands to clone the project repository and navigate into the project directory. ```bash git clone https://github.com/n-WN/mac_internal_audio_recording.git cd mac_internal_audio_recording ``` -------------------------------- ### verify_swift_source() Source: https://context7.com/n-wn/mac_internal_audio_recording/llms.txt Confirms that the `core.swift` source file exists in the current working directory. Raises `FileNotFoundError` if the file is not found. ```APIDOC ## verify_swift_source() ### Description Checks whether the required Swift source file is present in the current working directory. Returns the file path on success or raises `FileNotFoundError` so callers can handle the missing-source case cleanly before attempting compilation. ### Usage ```python import my_screen_capture_kit as audio_kit try: path = audio_kit.verify_swift_source() print(f"Swift source found at: {path}") except FileNotFoundError as e: print(f"Missing source: {e}") ``` ### Example Output (Success) ``` Swift source found at: core.swift ``` ### Example Output (Failure) ``` Missing source: core.swift not found ``` ``` -------------------------------- ### recorder Source: https://context7.com/n-wn/mac_internal_audio_recording/llms.txt Low-level command-line interface for the Swift audio capture binary. It captures system audio and/or microphone audio, saving it to WAV files. ```APIDOC ## recorder ### Description Low-level command-line interface for the Swift audio capture binary. It captures system audio and/or microphone audio, saving it to WAV files. ### Parameters - **output_path** (string) - Required - The path where the audio file will be saved. - **duration_seconds** (integer) - Required - The duration of the recording in seconds. Use 86400 for continuous recording. - **recording_type** (string) - Required - The type of audio to record. Valid values are 'internal', 'microphone', or 'both'. ### Request Example ```bash # Record internal audio for 15 seconds ./recorder output/system_audio.wav 15 internal # Record microphone only for 30 seconds ./recorder output/mic_audio.wav 30 microphone # Record both simultaneously for 60 seconds ./recorder output/session.wav 60 both # Continuous recording interrupted with Ctrl+C ./recorder output/stream.wav 86400 internal ``` ``` -------------------------------- ### Create Output Directory with Python Source: https://context7.com/n-wn/mac_internal_audio_recording/llms.txt Idempotently creates the 'output/' folder if it does not exist. This function is called automatically by `generate_output_filename()` but can be invoked independently. ```python import my_screen_capture_kit as audio_kit import os # Directory does not exist yet audio_kit.ensure_output_folder() # Prints: "Created output folder: output" print(os.path.isdir("output")) # True # Calling again when folder already exists is a no-op audio_kit.ensure_output_folder() # No output printed ``` -------------------------------- ### Compile Swift Source to Executable in Python Source: https://context7.com/n-wn/mac_internal_audio_recording/llms.txt Compiles `core.swift` to a `recorder` binary if it doesn't exist or is older than the source. Returns `True` on success, `False` on failure. Subsequent calls are fast if the binary is up to date. ```python import my_screen_capture_kit as audio_kit # First run: compiles core.swift → produces ./recorder success = audio_kit.ensure_executable() if success: print("Recorder binary is ready.") else: print("Compilation failed — check that Xcode Command Line Tools are installed.") # Subsequent run (binary already up to date): returns True immediately, no recompile success = audio_kit.ensure_executable() # Output: True (no compiler output printed) ``` -------------------------------- ### Generate Timestamped WAV Output Filename in Python Source: https://context7.com/n-wn/mac_internal_audio_recording/llms.txt Ensures the `output/` directory exists and returns a timestamped WAV filename. The microphone counterpart path is derived within `core.swift`. ```python import my_screen_capture_kit as audio_kit path = audio_kit.generate_output_filename() print(path) # Output: "output/recording_20240615_143022.wav" # Running again one second later produces a unique name path2 = audio_kit.generate_output_filename() print(path2) # Output: "output/recording_20240615_143023.wav" ``` -------------------------------- ### ensure_executable() Source: https://context7.com/n-wn/mac_internal_audio_recording/llms.txt Compiles the Swift source code (`core.swift`) into an executable binary (`recorder`) if it doesn't exist or is outdated. Returns `True` on success, `False` on failure. ```APIDOC ## ensure_executable() ### Description Checks whether the `recorder` binary exists and is newer than `core.swift`. If not, it invokes `swiftc core.swift -o recorder` via subprocess. Returns `True` on success or `False` if compilation fails (printing the compiler's stderr). Subsequent runs skip compilation entirely when the binary is up to date, keeping startup fast. ### Usage ```python import my_screen_capture_kit as audio_kit # First run: compiles core.swift → produces ./recorder success = audio_kit.ensure_executable() if success: print("Recorder binary is ready.") else: print("Compilation failed — check that Xcode Command Line Tools are installed.") # Subsequent run (binary already up to date): returns True immediately, no recompile success = audio_kit.ensure_executable() ``` ### Example Output (First Run) ``` Recorder binary is ready. ``` ### Example Output (Subsequent Run) ``` True ``` ``` -------------------------------- ### Verify Swift Source File in Python Source: https://context7.com/n-wn/mac_internal_audio_recording/llms.txt Checks for the presence of the `core.swift` file in the current working directory. Raises `FileNotFoundError` if the source file is missing, allowing for clean error handling. ```python import my_screen_capture_kit as audio_kit try: path = audio_kit.verify_swift_source() print(f"Swift source found at: {path}") # Output: "Swift source found at: core.swift" except FileNotFoundError as e: print(f"Missing source: {e}") # Output: "Missing source: core.swift not found" ``` -------------------------------- ### Call Individual Benchmark Functions Source: https://context7.com/n-wn/mac_internal_audio_recording/llms.txt Import and call specific performance test functions directly for targeted profiling. These functions return average times or specific measurements. ```python from tests.performance_test import ( test_language_detection, test_message_translation, test_compilation_performance ) avg_lang = test_language_detection() # returns avg seconds over 10 runs avg_trans = test_message_translation() # returns avg seconds over 8 keys compile_t = test_compilation_performance() # returns compilation check time ``` -------------------------------- ### detect_system_language() Source: https://context7.com/n-wn/mac_internal_audio_recording/llms.txt Detects the system's current language by probing locale settings and environment variables. Returns a two-letter ISO language code. ```APIDOC ## detect_system_language() ### Description Probes the system locale using five progressive fallback methods: Python's `locale` module, environment variables (`LANG`, `LC_ALL`, `LC_MESSAGES`, `LANGUAGE`), and a macOS-specific `defaults read -g AppleLanguages` subprocess call. Returns a two-letter ISO language code. Used internally by `get_message()` to select the correct translation dictionary. ### Usage ```python import my_screen_capture_kit as audio_kit lang = audio_kit.detect_system_language() print(lang) ``` ### Example Output ``` 'en' ``` ### Example Output (Chinese System) ``` 'zh' ``` ``` -------------------------------- ### generate_output_filename() Source: https://context7.com/n-wn/mac_internal_audio_recording/llms.txt Generates a timestamped WAV output filename within an `output/` directory, creating the directory if it doesn't exist. Returns the full path. ```APIDOC ## generate_output_filename() ### Description Ensures the `output/` directory exists (creating it if necessary) and returns a full path of the form `output/recording_YYYYMMDD_HHMMSS.wav`. The microphone counterpart path is derived inside `core.swift` by appending `_mic` before the extension. ### Usage ```python import my_screen_capture_kit as audio_kit path = audio_kit.generate_output_filename() print(path) # Running again one second later produces a unique name path2 = audio_kit.generate_output_filename() print(path2) ``` ### Example Output ``` output/recording_20240615_143022.wav output/recording_20240615_143023.wav ``` ``` -------------------------------- ### Continuous Internal Audio Recording Source: https://github.com/n-wn/mac_internal_audio_recording/blob/main/README.md Initiates continuous recording of internal audio. Press Ctrl+C to stop and save the recording. This is the default behavior when no duration is specified. ```bash $ python my_screen_capture_kit.py macOS audio recording ======================================== 1. Record internal audio only 2. Record microphone only 3. Record both (internal + microphone) Choice: 1 Press Enter for continuous recording, or enter duration in seconds: Recording internal audio. Press Ctrl+C to stop and save. # Press Ctrl+C when done Recording stopped by user. ``` -------------------------------- ### ensure_output_folder() Source: https://context7.com/n-wn/mac_internal_audio_recording/llms.txt Idempotently creates the 'output/' directory if it does not exist. This function is called automatically by `generate_output_filename` but can be invoked manually. ```APIDOC ## ensure_output_folder() ### Description Idempotently creates the 'output/' directory if it does not exist. This function is called automatically by `generate_output_filename` but can be invoked manually. ### Request Example ```python import my_screen_capture_kit as audio_kit audio_kit.ensure_output_folder() ``` ``` -------------------------------- ### Retrieve Localized Message String in Python Source: https://context7.com/n-wn/mac_internal_audio_recording/llms.txt Looks up a translation key in the MESSAGES dictionary for the detected system language, falling back to English if the key is missing. Formats the result with keyword arguments and returns a plain string. ```python import my_screen_capture_kit as audio_kit # Simple key lookup print(audio_kit.get_message('macos_audio_recording')) # English output: "macOS audio recording" # Chinese output: "macOS 音频录制" # Key with format parameters print(audio_kit.get_message('starting_recording', duration=30, output_filepath='output/recording_20240101_120000.wav')) # English output: "Starting recording for 30 seconds. Output will be saved to: output/recording_20240101_120000.wav" # Missing key returns sentinel string instead of raising print(audio_kit.get_message('nonexistent_key')) # Output: "MISSING_TRANSLATION_nonexistent_key" ``` -------------------------------- ### get_message(key, **kwargs) Source: https://context7.com/n-wn/mac_internal_audio_recording/llms.txt Retrieves a localized message string based on a key, falling back to English if necessary. Supports formatting with keyword arguments. ```APIDOC ## get_message(key, **kwargs) ### Description Looks up a translation key in the `MESSAGES` dictionary for the detected system language, falls back to English if the key is missing in the current locale, and formats the result with any provided keyword arguments. Returns a plain string safe for printing. ### Usage ```python import my_screen_capture_kit as audio_kit # Simple key lookup print(audio_kit.get_message('macos_audio_recording')) # Key with format parameters print(audio_kit.get_message('starting_recording', duration=30, output_filepath='output/recording_20240101_120000.wav')) # Missing key returns sentinel string instead of raising print(audio_kit.get_message('nonexistent_key')) ``` ### Example Output (English) ``` macOS audio recording Starting recording for 30 seconds. Output will be saved to: output/recording_20240101_120000.wav MISSING_TRANSLATION_nonexistent_key ``` ### Example Output (Chinese) ``` macOS 音频录制 Starting recording for 30 seconds. Output will be saved to: output/recording_20240101_120000.wav MISSING_TRANSLATION_nonexistent_key ``` ``` -------------------------------- ### Performance Test Output Source: https://context7.com/n-wn/mac_internal_audio_recording/llms.txt This output details the performance metrics of various components, including language detection, message translation, file operations, and compilation. ```text 🚀 macOS Internal Audio Recording - Performance Tests ============================================================ 🧪 Testing language detection... Average language detection time: 0.0003s Min time: 0.0002s, Max time: 0.0008s 🧪 Testing message translation... Average message translation time: 0.0004s Tested 8 keys 🧪 Testing file operations... Swift source verification: 0.0001s Output folder creation: 0.0000s Filename generation: 0.0001s 🧪 Testing Swift compilation... Executable exists, testing smart compilation... Smart compilation check: 0.0001s 📊 Performance Summary ============================== language_detection : 0.0003s message_translation : 0.0004s file_operations : 0.0002s compilation : 0.0001s startup : 0.0021s memory_usage : 0.12 MB cpu_usage : 2.4% 🎯 Performance Assessment ============================== ✅ Startup performance: Excellent (< 0.1s) ✅ Memory usage: Excellent (< 10 MB) ✅ Compilation: Fast (< 2s) 💡 Recommendations ==================== • CPU usage is very low - excellent efficiency • Overall performance is excellent! ``` -------------------------------- ### Detect System Language in Python Source: https://context7.com/n-wn/mac_internal_audio_recording/llms.txt Probes the system locale using multiple fallback methods to return a two-letter ISO language code. Used internally for selecting translation dictionaries. ```python import my_screen_capture_kit as audio_kit lang = audio_kit.detect_system_language() print(lang) # Output on an English macOS system: 'en' # Output on a Simplified Chinese macOS system: 'zh' ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.