### Install pybind11 using vcpkg Source: https://github.com/yannickjadoul/parselmouth/blob/master/pybind11/docs/installing.rst Install pybind11 using the vcpkg dependency manager. This involves cloning vcpkg, bootstrapping, integrating, and then installing pybind11. ```bash git clone https://github.com/Microsoft/vcpkg.git cd vcpkg ./bootstrap-vcpkg.sh ./vcpkg integrate install vcpkg install pybind11 ``` -------------------------------- ### Add Mock Install Target and Tests Source: https://github.com/yannickjadoul/parselmouth/blob/master/pybind11/tests/test_cmake_build/CMakeLists.txt Creates a mock installation target and adds build tests for installed components. This is executed only if `PYBIND11_INSTALL` is enabled and includes conditional logic for PyPy. ```cmake if(PYBIND11_INSTALL) add_custom_target( mock_install ${CMAKE_COMMAND} "-DCMAKE_INSTALL_PREFIX=${pybind11_BINARY_DIR}/mock_install" -P "${pybind11_BINARY_DIR}/cmake_install.cmake") pybind11_add_build_test(installed_function INSTALL) pybind11_add_build_test(installed_target INSTALL) if(NOT ("${PYTHON_MODULE_EXTENSION}" MATCHES "pypy" OR "${Python_INTERPRETER_ID}" STREQUAL "PyPy" )) pybind11_add_build_test(installed_embed INSTALL) endif() endif() ``` -------------------------------- ### Installing Library and Export Configuration Source: https://github.com/yannickjadoul/parselmouth/blob/master/pybind11/tests/test_cmake_build/subdirectory_embed/CMakeLists.txt Configures the installation of 'test_embed_lib' and its associated export targets. ```cmake install( TARGETS test_embed_lib EXPORT test_export ARCHIVE DESTINATION bin LIBRARY DESTINATION lib RUNTIME DESTINATION lib) install(EXPORT test_export DESTINATION lib/cmake/test_export/test_export-Targets.cmake) ``` -------------------------------- ### Project and Subdirectory Setup Source: https://github.com/yannickjadoul/parselmouth/blob/master/pybind11/tests/test_cmake_build/subdirectory_target/CMakeLists.txt Initializes the project and adds the pybind11 subdirectory. This is a standard CMake setup for including external libraries or modules. ```cmake project(test_subdirectory_target CXX) add_subdirectory("${pybind11_SOURCE_DIR}" pybind11) ``` -------------------------------- ### Example usage of split pybind11 modules Source: https://github.com/yannickjadoul/parselmouth/blob/master/pybind11/docs/faq.rst Shows how to import and use functions from a pybind11 module that has been split into multiple compilation units. This example assumes the 'example' module has been built from separate C++ files. ```pycon >>> import example >>> example.add(1, 2) 3 >>> example.sub(1, 1) 0 ``` -------------------------------- ### Usage Example for gen-unicode Source: https://github.com/yannickjadoul/parselmouth/blob/master/praat/generate/Unicode/gen-unicode-ctype.c.html This is a command-line usage example for the gen-unicode utility. It shows how to invoke the program with the path to the UnicodeData file and a version number. ```bash $ gen-unicode /usr/local/share/Unidata/UnicodeData.txt 3.1 ``` -------------------------------- ### Install Parselmouth Source: https://github.com/yannickjadoul/parselmouth/blob/master/README.md Install Parselmouth using pip. Use -U to update to the latest release. ```bash pip install praat-parselmouth ``` ```bash pip install -U praat-parselmouth ``` -------------------------------- ### Install pybind11 with global access using Pip Source: https://github.com/yannickjadoul/parselmouth/blob/master/pybind11/docs/installing.rst Install pybind11 with global access using pip. This method is not recommended for system Python installations as it adds files to system directories. ```bash pip install "pybind11[global]" ``` -------------------------------- ### Install pybind11 using Pip Source: https://github.com/yannickjadoul/parselmouth/blob/master/pybind11/docs/installing.rst Install pybind11 as a Python package using pip. This is the recommended method for most Python projects. ```bash pip install pybind11 ``` -------------------------------- ### Install pybind11 with CMake Source: https://github.com/yannickjadoul/parselmouth/blob/master/pybind11/docs/compiling.rst Use these CMake commands to build and install pybind11 from source. Supports classic CMake and newer versions with build directories. ```bash # Classic CMake cd pybind11 mkdir build cd build cmake .. make install ``` ```bash # CMake 3.15+ cd pybind11 cmake -S . -B build cmake --build build -j 2 # Build on 2 cores cmake --install build ``` -------------------------------- ### Setup.py with Pybind11Extension Source: https://github.com/yannickjadoul/parselmouth/blob/master/pybind11/docs/compiling.rst Integrate pybind11 into your setup.py using Pybind11Extension. Ensure pybind11 is installed before building. ```python from glob import glob from setuptools import setup from pybind11.setup_helpers import Pybind11Extension ext_modules = [ Pybind11Extension( "python_example", sorted(glob("src/*.cpp")), # Sort source files for reproducibility ), ] setup( ..., ext_modules=ext_modules ) ``` -------------------------------- ### Install Build Tools and Graphics/Sound Packages on Ubuntu Source: https://github.com/yannickjadoul/parselmouth/blob/master/praat/README.md Installs essential build tools and libraries for graphics and sound support on Ubuntu systems. These are prerequisites for compiling Praat. ```bash sudo apt install make gcc g++ rsync pkg-config sudo apt install libgtk-3-dev sudo apt install libasound2-dev sudo apt install libpulse-dev sudo apt install libjack-dev ``` -------------------------------- ### Install pybind11 using Homebrew Source: https://github.com/yannickjadoul/parselmouth/blob/master/pybind11/docs/installing.rst Install pybind11 using the Homebrew package manager on macOS or Linux. This provides a system-wide installation. ```bash brew install pybind11 ``` -------------------------------- ### Install pybind11-mkdoc for Tools Source: https://github.com/yannickjadoul/parselmouth/blob/master/pybind11/docs/upgrade.rst The tools/clang submodule and tools/mkdoc.py have moved to a standalone package, pybind11-mkdoc. Install it via pip if you were using these tools. ```bash pip install pybind11-mkdoc ``` -------------------------------- ### Install Pybind11 Headers and Config Files Source: https://github.com/yannickjadoul/parselmouth/blob/master/pybind11/CMakeLists.txt Installs pybind11 headers and CMake configuration files. This snippet configures the installation path for pybind11Config.cmake and its associated version file, ensuring proper package discovery. ```cmake if(PYBIND11_INSTALL) install(DIRECTORY ${pybind11_INCLUDE_DIR}/pybind11 DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) set(PYBIND11_CMAKECONFIG_INSTALL_DIR "${CMAKE_INSTALL_DATAROOTDIR}/cmake/${PROJECT_NAME}" CACHE STRING "install path for pybind11Config.cmake") configure_package_config_file( tools/${PROJECT_NAME}Config.cmake.in "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake" INSTALL_DESTINATION ${PYBIND11_CMAKECONFIG_INSTALL_DIR}) if(CMAKE_VERSION VERSION_LESS 3.14) # Remove CMAKE_SIZEOF_VOID_P from ConfigVersion.cmake since the library does # not depend on architecture specific settings or libraries. set(_PYBIND11_CMAKE_SIZEOF_VOID_P ${CMAKE_SIZEOF_VOID_P}) unset(CMAKE_SIZEOF_VOID_P) write_basic_package_version_file( ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake VERSION ${PROJECT_VERSION} COMPATIBILITY AnyNewerVersion) set(CMAKE_SIZEOF_VOID_P ${_PYBIND11_CMAKE_SIZEOF_VOID_P}) else() # CMake 3.14+ natively supports header-only libraries write_basic_package_version_file( ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake VERSION ${PROJECT_VERSION} COMPATIBILITY AnyNewerVersion ARCH_INDEPENDENT) endif() install( FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake tools/FindPythonLibsNew.cmake tools/pybind11Common.cmake tools/pybind11Tools.cmake tools/pybind11NewTools.cmake DESTINATION ${PYBIND11_CMAKECONFIG_INSTALL_DIR}) if(NOT PYBIND11_EXPORT_NAME) set(PYBIND11_EXPORT_NAME "${PROJECT_NAME}Targets") endif() install(TARGETS pybind11_headers EXPORT "${PYBIND11_EXPORT_NAME}") install( EXPORT "${PYBIND11_EXPORT_NAME}" NAMESPACE "pybind11::" DESTINATION ${PYBIND11_CMAKECONFIG_INSTALL_DIR}) # Uninstall target if(PYBIND11_MASTER_PROJECT) configure_file("${CMAKE_CURRENT_SOURCE_DIR}/tools/cmake_uninstall.cmake.in" "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake" IMMEDIATE @ONLY) add_custom_target(uninstall COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake) endif() endif() ``` -------------------------------- ### Include pybind11 header and namespace Source: https://github.com/yannickjadoul/parselmouth/blob/master/pybind11/docs/basics.rst These C++ lines are assumed to be present in all pybind11 code examples for brevity. Include the main header and set up the pybind11 namespace. ```cpp #include namespace py = pybind11; ``` -------------------------------- ### Install Parselmouth using pip Source: https://github.com/yannickjadoul/parselmouth/blob/master/docs/installation.rst Use this command to install the Parselmouth Python library. Ensure you are using a recent version of pip. ```bash pip install praat-parselmouth ``` -------------------------------- ### Compile and run tests on Linux/macOS Source: https://github.com/yannickjadoul/parselmouth/blob/master/pybind11/docs/basics.rst Use this bash command to compile and run pybind11 test cases on Linux or macOS after installing prerequisites. ```bash mkdir build cd build cmake .. make check -j 4 ``` -------------------------------- ### Multiple Properties Example Source: https://github.com/yannickjadoul/parselmouth/blob/master/praat/generate/Unicode/UAX Shows how multiple properties for a character are specified in a single data file line. ```text 03D2 ; FC_NFKC; 03C5 # L& GREEK UPSILON WITH HOOK SYMBOL ``` ```text 03D3 ; FC_NFKC; 03CD # L& GREEK UPSILON WITH ACUTE AND HOOK SYMBOL ``` -------------------------------- ### Batch Processing Example Source: https://context7.com/yannickjadoul/parselmouth/llms.txt Demonstrates how to use Parselmouth with Python's standard libraries and pandas for batch processing and analysis of multiple audio files. ```APIDOC ## Batch Processing Example ### Description Efficiently process and analyze multiple audio files using Parselmouth with Python's standard libraries and pandas. ### Request Example ```python import parselmouth import pandas as pd import glob import os # Batch process all WAV files in a directory for audio_file in glob.glob("audio/*.wav"): print(f"Processing {audio_file}...") sound = parselmouth.Sound(audio_file) # Apply processing sound.pre_emphasize() # Save processed file output_path = os.path.splitext(audio_file)[0] + "_processed.wav" sound.save(output_path, "WAV") # Batch analysis with pandas def analyze_audio(filepath): sound = parselmouth.Sound(filepath) pitch = sound.to_pitch() harmonicity = sound.to_harmonicity() pitch_values = pitch.selected_array['frequency'] pitch_values = pitch_values[pitch_values > 0] # Remove unvoiced hnr_values = harmonicity.values hnr_values = hnr_values[hnr_values != -200] # Remove undefined return { 'mean_pitch': pitch_values.mean() if len(pitch_values) > 0 else None, 'mean_hnr': hnr_values.mean() if len(hnr_values) > 0 else None, 'duration': sound.xmax - sound.xmin } # Process files listed in CSV df = pd.read_csv("file_list.csv") results = df['filepath'].apply(lambda f: pd.Series(analyze_audio(f))) df = pd.concat([df, results], axis=1) df.to_csv("analysis_results.csv", index=False) ``` ``` -------------------------------- ### Example Deprecation Warning for Old Constructors Source: https://github.com/yannickjadoul/parselmouth/blob/master/pybind11/docs/upgrade.rst This is an example of a runtime warning that may appear during module initialization when using old-style placement-new constructors in debug mode. ```none pybind11-bound class 'mymodule.Foo' is using an old-style placement-new '__init__' which has been deprecated. See the upgrade guide in pybind11's docs. ``` -------------------------------- ### Module-Local Class Binding Usage Example Source: https://github.com/yannickjadoul/parselmouth/blob/master/pybind11/docs/advanced/classes.rst Shows how a class binding defined in one module can be used and returned from another module, demonstrating the concept of module-local bindings. ```cpp // In the module2.cpp binding code for module2: m.def("create_pet", [](std::string name) { return new Pet(name); }); ``` -------------------------------- ### Running Flask Server in a Jupyter Notebook Source: https://github.com/yannickjadoul/parselmouth/blob/master/docs/examples/web_service.ipynb This Python code starts the Flask server in a separate subprocess within a Jupyter environment. It forwards the server's output to the notebook's stdout and stderr, allowing for integrated testing. A short delay is included to ensure the server has started. ```python import os import subprocess import sys import time # Start a subprocess that runs the Flask server p = subprocess.Popen([sys.executable, "-m", "flask", "run"], env=dict(**os.environ, FLASK_APP="server.py"), stdout=subprocess.PIPE, stderr=subprocess.PIPE) # Start two subthreads that forward the output from the Flask server to the output of the Jupyter notebook def forward(i, o): while p.poll() is None: l = i.readline().decode('utf-8') if l: o.write("[SERVER] " + l) import threading threading.Thread(target=forward, args=(p.stdout, sys.stdout)).start() threading.Thread(target=forward, args=(p.stderr, sys.stderr)).start() # Let's give the server a bit of time to make sure it has started time.sleep(2) ``` -------------------------------- ### Compile pybind11 module on Linux Source: https://github.com/yannickjadoul/parselmouth/blob/master/pybind11/docs/basics.rst Use this command to compile the C++ example into a Python extension module on Linux. It includes necessary compiler flags and pybind11 include paths. ```bash c++ -O3 -Wall -shared -std=c++11 -fPIC $(python3 -m pybind11 --includes) example.cpp -o example$(python3-config --extension-suffix) ``` -------------------------------- ### Smart Recompilation with Pybind11 Source: https://github.com/yannickjadoul/parselmouth/blob/master/pybind11/docs/compiling.rst Implement smart recompilation to avoid rebuilding unchanged files in simple cases using naive_recompile. This works with editable installs and does not check headers. ```python from pybind11.setup_helpers import ParallelCompile, naive_recompile SmartCompile("NPY_NUM_BUILD_JOBS", needs_recompile=naive_recompile).install() ``` -------------------------------- ### Test Praat Barren (Ubuntu Command Line) Source: https://github.com/yannickjadoul/parselmouth/blob/master/praat/README.md Execute this command in the Ubuntu terminal to verify the installation and version of the 'praat_barren' executable after building it. ```bash # on Ubuntu command line praatb --version ``` -------------------------------- ### Test Praat No-GUI (Ubuntu Command Line) Source: https://github.com/yannickjadoul/parselmouth/blob/master/praat/README.md Run this command in the Ubuntu terminal to check the installation and version of the 'praat_nogui' executable after it has been built. ```bash # on Ubuntu command line praatn --version ``` -------------------------------- ### Specialize pybind11 Holder Helper for Custom Get Method Source: https://github.com/yannickjadoul/parselmouth/blob/master/pybind11/docs/advanced/smart_ptrs.rst Specialize `pybind11::detail::holder_helper` if your custom smart pointer's method to access the raw pointer is not named `.get()`. This example shows how to use `.getPointer()` instead. ```cpp namespace pybind11 { namespace detail { template struct holder_helper> { // <-- specialization static const T *get(const SmartPtr &p) { return p.getPointer(); } }; }} ``` -------------------------------- ### Setup.py with build_ext for C++ Standard Source: https://github.com/yannickjadoul/parselmouth/blob/master/pybind11/docs/compiling.rst Use build_ext command override in setup.py to automatically search for the highest supported C++ standard for Pybind11Extensions. ```python from glob import glob from setuptools import setup from pybind11.setup_helpers import Pybind11Extension, build_ext ext_modules = [ Pybind11Extension( "python_example", sorted(glob("src/*.cpp")), ), ] setup( ..., cmdclass={"build_ext": build_ext}, ext_modules=ext_modules ) ``` -------------------------------- ### Using pybind11.setup_helpers with Setuptools Source: https://github.com/yannickjadoul/parselmouth/blob/master/pybind11/docs/changelog.rst Utilize the pybind11.setup_helpers module for easier integration with setuptools. ```python # setup.py from setuptools import setup from pybind11.setup_helpers import Pybind11Extension, build_ext setup( ext_modules=[ Pybind11Extension("example", ["example.cpp"]), ], cmdclass={"build_ext": build_ext}, ) ``` -------------------------------- ### Sound - Loading and Creating Audio Source: https://context7.com/yannickjadoul/parselmouth/llms.txt Demonstrates how to load audio from files and create Sound objects from NumPy arrays, along with accessing basic audio properties. ```APIDOC ## Sound - Loading and Creating Audio ### Description The `Sound` class is the primary interface for working with audio data. It can load audio files, create sounds from NumPy arrays, and provides access to audio properties and transformations. ### Method Various methods are demonstrated for loading, creating, and accessing properties of `Sound` objects. ### Endpoint N/A (This is a library API, not a web endpoint) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```python import parselmouth import numpy as np # Load audio from file sound = parselmouth.Sound("audio/speech.wav") # Create sound from NumPy array sample_rate = 44100 duration = 1.0 t = np.linspace(0, duration, int(sample_rate * duration)) waveform = np.sin(2 * np.pi * 440 * t) # 440 Hz sine wave sound_from_array = parselmouth.Sound(waveform, sampling_frequency=sample_rate) # Access sound properties print(f"Duration: {sound.xmax - sound.xmin} seconds") print(f"Sampling frequency: {sound.sampling_frequency} Hz") print(f"Number of channels: {sound.n_channels}") print(f"Number of samples: {sound.n_samples}") # Get time values and amplitude values as NumPy arrays time_values = sound.xs() amplitude_values = sound.values # Shape: (n_channels, n_samples) # Extract part of the sound sound_part = sound.extract_part(from_time=0.5, to_time=1.5, preserve_times=True) # Extract specific channels left_channel = sound.extract_left_channel() right_channel = sound.extract_right_channel() mono_sound = sound.convert_to_mono() ``` ### Response #### Success Response (200) Output includes printed information about sound properties and created `Sound` objects. #### Response Example ``` Duration: 2.5 seconds Sampling frequency: 44100 Hz Number of channels: 1 Number of samples: 110250 ``` ``` -------------------------------- ### Verify Parselmouth Installation in PsychoPy Shell Source: https://github.com/yannickjadoul/parselmouth/blob/master/docs/installation.rst After installing Parselmouth, open the PsychoPy Coder interface and use this command in the Shell tab to check if the import is successful. An error indicates a problem with the installation. ```python import parselmouth ``` -------------------------------- ### Code Point Label Example: Reserved Source: https://github.com/yannickjadoul/parselmouth/blob/master/praat/generate/Unicode/UAX Example of a code point label for a reserved character, using the 'Cn' General_Category. ```text 2065 ; Default_Ignorable_Code_Point # Cn ``` -------------------------------- ### PEP 517 Build Backend Configuration Source: https://github.com/yannickjadoul/parselmouth/blob/master/pybind11/docs/compiling.rst This `pyproject.toml` snippet defines the build system requirements for a PEP 517 compliant project. It requires setuptools version 42 or higher and specifies setuptools.build_meta as the build backend. ```toml requires = ["setuptools>=42", "wheel", "pybind11~=2.6.1"] build-backend = "setuptools.build_meta" ``` -------------------------------- ### Install pybind11 using conda-forge Source: https://github.com/yannickjadoul/parselmouth/blob/master/pybind11/docs/installing.rst Install pybind11 using the conda package manager from the conda-forge channel. This is suitable for environments managed by Conda. ```bash conda install -c conda-forge pybind11 ``` -------------------------------- ### Basic Flask Server for Pitch Track Estimation Source: https://github.com/yannickjadoul/parselmouth/blob/master/docs/examples/web_service.ipynb This Python script sets up a Flask web server that accepts audio files via POST requests. It uses Parselmouth to calculate the pitch track and returns the frequencies as a JSON list. Ensure Flask and Parselmouth are installed. ```python from flask import Flask, request, jsonify import tempfile app = Flask(__name__) @app.route('/pitch_track', methods=['POST']) def pitch_track(): import parselmouth # Save the file that was sent, and read it into a parselmouth.Sound with tempfile.NamedTemporaryFile() as tmp: tmp.write(request.files['audio'].read()) sound = parselmouth.Sound(tmp.name) # Calculate the pitch track with Parselmouth pitch_track = sound.to_pitch().selected_array['frequency'] # Convert the NumPy array into a list, then encode as JSON to send back return jsonify(list(pitch_track)) ``` -------------------------------- ### Set Relative Install Directory Source: https://github.com/yannickjadoul/parselmouth/blob/master/pybind11/CMakeLists.txt Sets the CMAKE_INSTALL_INCLUDEDIR based on Python include directories. This is used to ensure headers are installed in the correct relative path. ```cmake if(USE_PYTHON_INCLUDE_DIR AND DEFINED Python_INCLUDE_DIRS) file(RELATIVE_PATH CMAKE_INSTALL_INCLUDEDIR ${CMAKE_INSTALL_PREFIX} ${Python_INCLUDE_DIRS}) elseif(USE_PYTHON_INCLUDE_DIR AND DEFINED PYTHON_INCLUDE_DIR) file(RELATIVE_PATH CMAKE_INSTALL_INCLUDEDIR ${CMAKE_INSTALL_PREFIX} ${PYTHON_INCLUDE_DIRS}) endif() ``` -------------------------------- ### Load and Create Sound Objects in Parselmouth Source: https://context7.com/yannickjadoul/parselmouth/llms.txt Demonstrates loading audio from a file, creating a Sound object from a NumPy array, accessing properties, extracting parts, and selecting channels. ```python import parselmouth import numpy as np # Load audio from file sound = parselmouth.Sound("audio/speech.wav") # Create sound from NumPy array sample_rate = 44100 duration = 1.0 t = np.linspace(0, duration, int(sample_rate * duration)) waveform = np.sin(2 * np.pi * 440 * t) # 440 Hz sine wave sound_from_array = parselmouth.Sound(waveform, sampling_frequency=sample_rate) # Access sound properties print(f"Duration: {sound.xmax - sound.xmin} seconds") print(f"Sampling frequency: {sound.sampling_frequency} Hz") print(f"Number of channels: {sound.n_channels}") print(f"Number of samples: {sound.n_samples}") # Get time values and amplitude values as NumPy arrays time_values = sound.xs() amplitude_values = sound.values # Shape: (n_channels, n_samples) # Extract part of the sound sound_part = sound.extract_part(from_time=0.5, to_time=1.5, preserve_times=True) # Extract specific channels left_channel = sound.extract_left_channel() right_channel = sound.extract_right_channel() mono_sound = sound.convert_to_mono() ``` -------------------------------- ### Upgrade Parselmouth using pip Source: https://github.com/yannickjadoul/parselmouth/blob/master/docs/installation.rst To update your installed Parselmouth to the latest version, use the -U or --upgrade flag with the pip install command. ```bash pip install -U praat-parselmouth ``` -------------------------------- ### C++ Type Name in Docstring Example Source: https://github.com/yannickjadoul/parselmouth/blob/master/pybind11/docs/advanced/misc.rst An example showing how C++ type names appear in docstrings when custom types are not yet registered with pybind11. ```text | __init__(...) | __init__(self: example.Foo, arg0: ns::Bar) -> None ^^^^^^^ ``` -------------------------------- ### Configure Makefile for Barren Build (No GUI or Graphics) Source: https://github.com/yannickjadoul/parselmouth/blob/master/praat/README.md Copies the makefile definitions for compiling the most minimal Praat executable, excluding both GUI and graphics capabilities. This is for computation-only needs. ```bash cp makefiles/makefile.defs.linux.barren ./makefile.defs ``` -------------------------------- ### Manually Install Parselmouth in Standalone PsychoPy Source: https://github.com/yannickjadoul/parselmouth/blob/master/docs/installation.rst Steps to manually install Parselmouth in a standalone PsychoPy version by downloading a wheel file, extracting it, and adding its path to PsychoPy preferences. ```python import sys; print(sys.version_info) ``` ```python import platform; print(platform.architecture()[0]) ``` -------------------------------- ### Create Linux Praat Distribution Package (Intel64) Source: https://github.com/yannickjadoul/parselmouth/blob/master/praat/README.md Creates a gzipped tar archive for the Linux Intel64 Praat executable and places it in the distribution directory. This command should be run from the Linux bin directory. ```bash # on Mac command line ( cd ~/Dropbox/Praats/bin/linux-intel64 && tar cvf praat${PRAAT_VERSION}_linux-intel64.tar praat && gzip praat${PRAAT_VERSION}_linux-intel64.tar && mv praat${PRAAT_VERSION}_linux-intel64.tar.gz $PRAAT_WWW ) ``` -------------------------------- ### Run PsychoPy Installation Script Source: https://github.com/yannickjadoul/parselmouth/blob/master/docs/installation.rst For standalone PsychoPy versions that do not support external library installation via pip, run this Python script from within the PsychoPy Coder interface. ```python import sys import platform print(sys.version_info) print(platform.architecture()[0]) ``` -------------------------------- ### Pybind11 module definition for functional examples Source: https://github.com/yannickjadoul/parselmouth/blob/master/pybind11/docs/advanced/cast/functional.rst This C++ code defines a pybind11 module that exposes the previously defined C++ functional examples to Python. Ensure `` is included. ```cpp #include PYBIND11_MODULE(example, m) { m.def("func_arg", &func_arg); m.def("func_ret", &func_ret); m.def("func_cpp", &func_cpp); } ``` -------------------------------- ### Example of NumPy slice with Eigen Source: https://github.com/yannickjadoul/parselmouth/blob/master/pybind11/docs/advanced/cast/eigen.rst This example demonstrates using Eigen with a NumPy slice to perform operations on specific elements. It multiplies coefficients on even rows and specific columns by 2. ```python # a = np.array(...) scale_by_2(myarray[0::2, 2:9:3]) ``` -------------------------------- ### Generalized Unpacking with Keyword Arguments Source: https://github.com/yannickjadoul/parselmouth/blob/master/pybind11/docs/advanced/pycpp/object.rst Demonstrates generalized unpacking of keyword arguments according to PEP448, allowing multiple `**kwargs` and keyword literals to be mixed in a function call. ```cpp py::dict kwargs1 = py::dict("number"_a=1234); py::dict kwargs2 = py::dict("to"_a=some_instance); f(**kwargs1, "say"_a="hello", **kwargs2); ``` -------------------------------- ### Use pybind11-config for pybind11 Source: https://github.com/yannickjadoul/parselmouth/blob/master/pybind11/docs/changelog.rst Use 'pybind11-config' as an alternative to 'python -m pybind11' when your PATH is configured. ```bash pybind11-config ``` -------------------------------- ### Install Parselmouth using Python Module Pip Source: https://github.com/yannickjadoul/parselmouth/blob/master/docs/installation.rst When multiple Python versions are present, use this command to ensure pip is associated with the correct Python installation. This is particularly useful on OS X. ```bash python -m pip install praat-parselmouth ``` -------------------------------- ### Project Definition Source: https://github.com/yannickjadoul/parselmouth/blob/master/pybind11/tests/CMakeLists.txt Defines the main project as 'pybind11_tests' with CXX as the language. This is a standard CMake command to initialize a project. ```cmake project(pybind11_tests CXX) ``` -------------------------------- ### Set and Get Window Text with Wide Strings Source: https://github.com/yannickjadoul/parselmouth/blob/master/pybind11/docs/advanced/cast/strings.rst Demonstrates setting and getting window text using `std::wstring` which is converted to/from Python strings. Assumes UTF-16 encoding for wide strings. ```c++ #define UNICODE #include m.def("set_window_text", [](HWND hwnd, std::wstring s) { // Call SetWindowText with null-terminated UTF-16 string ::SetWindowText(hwnd, s.c_str()); } ); m.def("get_window_text", [](HWND hwnd) { const int buffer_size = ::GetWindowTextLength(hwnd) + 1; auto buffer = std::make_unique< wchar_t[] >(buffer_size); ::GetWindowText(hwnd, buffer.data(), buffer_size); std::wstring text(buffer.get()); // wstring will be converted to Python str return text; } ); ``` -------------------------------- ### Binding Constructors with pybind11 Source: https://github.com/yannickjadoul/parselmouth/blob/master/pybind11/docs/advanced/classes.rst Demonstrates different ways to bind constructors using pybind11, including default, overloaded, and alias constructors. ```cpp .def(py::init([]() { return new Example(); })) // Two callbacks: .def(py::init([]() { return new Example(); } /* no alias needed */, []() { return new PyExample(); } /* alias needed */)) // *Always* returns an alias instance (like py::init_alias<>()) .def(py::init([]() { return new PyExample(); })) ; ``` -------------------------------- ### Update Pip to Latest Version Source: https://github.com/yannickjadoul/parselmouth/blob/master/docs/installation.rst If the standard installation of Parselmouth fails or takes too long, try updating pip to its latest version. A recent pip version is often required for installing precompiled binary wheels. ```bash pip install -U pip ``` -------------------------------- ### Install Parselmouth from within Python Source: https://github.com/yannickjadoul/parselmouth/blob/master/docs/installation.rst This method allows installing Parselmouth directly from within a Python script or interpreter without needing to know the explicit path to the Python executable. It uses subprocess to call pip. ```python import sys, subprocess subprocess.call([sys.executable, '-m', 'pip', 'install', 'praat-parselmouth']) ``` -------------------------------- ### Load Audio File with Parselmouth Source: https://github.com/yannickjadoul/parselmouth/blob/master/docs/examples/pitch_manipulation.ipynb Import Parselmouth and load an audio file. This is the initial step for any audio manipulation task. ```python import parselmouth sound = parselmouth.Sound("audio/4_b.wav") ``` -------------------------------- ### Build and Upload Pybind11 Packages Source: https://github.com/yannickjadoul/parselmouth/blob/master/pybind11/docs/release.rst Steps to manually build source distributions (SDists) and wheels for pybind11 and upload them to PyPI using twine. Ensure your local directory is clean before building. ```bash python3 -m pip install build python3 -m build PYBIND11_SDIST_GLOBAL=1 python3 -m build twine upload dist/* ``` -------------------------------- ### Get pybind11 Type Object from Python Object Source: https://github.com/yannickjadoul/parselmouth/blob/master/pybind11/docs/advanced/classes.rst Use `py::type::of(ob)` to get the type object from any Python object. This function behaves similarly to Python's built-in `type(ob)`. ```python py::type::of(ob) ``` -------------------------------- ### Derived Property Definition Example Source: https://github.com/yannickjadoul/parselmouth/blob/master/praat/generate/Unicode/UAX This is an example of how derived properties are defined in UCD data files, showing set operations for character inclusion and exclusion. Always refer to the explicit listing in the data file as the normative definition. ```plaintext # Derived Property: ID_Start # Characters that can start an identifier. # Generated from: # Lu + Ll + Lt + Lm + Lo + Nl # + Other_ID_Start # - Pattern_Syntax # - Pattern_White_Space ``` -------------------------------- ### Display Function Signature with Keyword Arguments Source: https://github.com/yannickjadoul/parselmouth/blob/master/pybind11/docs/basics.rst Demonstrates how to view the function signature, including keyword argument names and types, using Python's `help()` function after the function has been bound with `py::arg`. ```pycon >>> help(example) .... FUNCTIONS add(...) Signature : (i: int, j: int) -> int A function which adds two numbers ``` -------------------------------- ### Define Raspberry Pi Build and Run Aliases Source: https://github.com/yannickjadoul/parselmouth/blob/master/praat/README.md Set up aliases in your Raspberry Pi's ~/.bash_aliases for building the project, running the application, and performing both actions. This simplifies the development workflow. ```bash alias praat-build="( cd ~/praats &&\ cp makefiles/makefile.defs.linux.rpi makefile.defs &&\ make -j4 )" alias praat="~/praats/praat" alias praat-run="praat-build && praat" ``` -------------------------------- ### Define Aliases for Praat Build and Run (Ubuntu) Source: https://github.com/yannickjadoul/parselmouth/blob/master/praat/README.md Add these definitions to your ~/.bash_aliases file to create shortcuts for building and running the standard Praat executable. Ensure the ORIGINAL_SOURCES path points to your Praat source code. ```bash # in Ubuntu:/home/yourname/.bash_aliases ORIGINAL_SOURCES="/Users/yourname/Dropbox/Praats/src" EXCLUDES='--exclude="*.xcodeproj" --exclude="Icon*" --exclude=".*" --exclude="*kanweg*"' alias praat-build="( cd ~/praats && \ rsync -rptvz $ORIGINAL_SOURCES/ $EXCLUDES . && \ cp makefiles/makefile.defs.linux.pulse makefile.defs && \ make -j15 )" alias praat="~/praats/praat" alias praat-run="praat-build && praat" ``` -------------------------------- ### Import Plotting Libraries Source: https://github.com/yannickjadoul/parselmouth/blob/master/docs/examples/web_service.ipynb Imports necessary libraries for plotting with Matplotlib and Seaborn. These should be installed prior to use. ```python import matplotlib.pyplot as plt import seaborn as sns ``` -------------------------------- ### Bind Local Extension Class (dogs.cpp) Source: https://github.com/yannickjadoul/parselmouth/blob/master/pybind11/docs/advanced/classes.rst Binds a local extension class 'Dog' inheriting from 'Pet' to Python. ```cpp py::class(m, "Dog") .def(py::init()); ``` -------------------------------- ### Comment Example: Character Range Source: https://github.com/yannickjadoul/parselmouth/blob/master/praat/generate/Unicode/UAX Demonstrates how character ranges are represented in comments, including the number of items. ```text 00BC..00BE ; Numeric # No \[3\] VULGAR FRACTION ONE QUARTER..VULGAR FRACTION THREE QUARTERS ``` -------------------------------- ### Define Aliases for Praat Barren Build and Run (Ubuntu) Source: https://github.com/yannickjadoul/parselmouth/blob/master/praat/README.md Configure these aliases in ~/.bash_aliases to build and run the 'praat_barren' executable, which is a version without a GUI. The setup mirrors the standard Praat build process but uses a different makefile definition. ```bash # in Ubuntu:~/.bash_aliases alias praatb-build="( cd ~/praatsb && \ rsync -rptvz $ORIGINAL_SOURCES/ $EXCLUDES . && \ cp makefiles/makefile.defs.linux.barren makefile.defs && \ make -j15 )" alias praatb="~/praatsb/praat_barren" alias praatb-run="praatb-build && praatb" ``` -------------------------------- ### Comment Example: Bengali Letter Source: https://github.com/yannickjadoul/parselmouth/blob/master/praat/generate/Unicode/UAX Illustrates the common comment format including General_Category and character name. ```text 09B2 ; Bengali # Lo BENGALI LETTER LA ``` -------------------------------- ### Get Spectrogram Power at Specific Point Source: https://context7.com/yannickjadoul/parselmouth/llms.txt Retrieves the power value of the spectrogram at a given time and frequency. ```python # Get power at specific time and frequency power_at_point = spectrogram.get_power_at(time=0.5, frequency=1000.0) ``` -------------------------------- ### Example of Strict Constructor Binding in C++ Source: https://github.com/yannickjadoul/parselmouth/blob/master/pybind11/docs/upgrade.rst Demonstrates the stricter py::init<> binding rules in C++. An exact match for the argument type is required, otherwise a compile-time error occurs. ```cpp struct Example { Example(int &); }; py::class_(m, "Example") .def(py::init()); // OK, exact match // .def(py::init()); // compile-time error, mismatch ``` -------------------------------- ### Project and Pybind11 Configuration Source: https://github.com/yannickjadoul/parselmouth/blob/master/pybind11/tests/test_cmake_build/subdirectory_embed/CMakeLists.txt Defines the project name and configures pybind11 settings, including installation and export name. ```cmake project(test_subdirectory_embed CXX) set(PYBIND11_INSTALL ON CACHE BOOL "") set(PYBIND11_EXPORT_NAME test_export) ``` -------------------------------- ### Use PYBIND11_MODULE or module_::create_extension_module Source: https://github.com/yannickjadoul/parselmouth/blob/master/pybind11/docs/upgrade.rst Deprecated public constructors of py::module_. Use PYBIND11_MODULE or module_::create_extension_module instead. ```cpp PYBIND11_MODULE ``` ```cpp module_::create_extension_module ``` -------------------------------- ### Comment Example: Greek Letter with Alias Source: https://github.com/yannickjadoul/parselmouth/blob/master/praat/generate/Unicode/UAX Shows the use of 'L&' as an alias for derived LC value in comments. ```text 0386 ; Greek # L& GREEK CAPITAL LETTER ALPHA WITH TONOS ``` -------------------------------- ### Python Class with Dynamic Attributes Source: https://github.com/yannickjadoul/parselmouth/blob/master/pybind11/docs/classes.rst Example of a native Python class demonstrating dynamic attribute addition and overwriting. ```pycon >>> class Pet: ... name = 'Molly' ... >>> p = Pet() >>> p.name = 'Charly' # overwrite existing >>> p.age = 2 # dynamically add a new attribute ```