### Install ffmpeg Source: https://github.com/ina-foss/inaspeechsegmenter/blob/master/tutorials/Demo_INASPeechSegmenter.ipynb Installs the ffmpeg command-line utility, which may be required in some environments. ```bash ! apt install ffmpeg ``` -------------------------------- ### Install inaSpeechSegmenter from Source Source: https://github.com/ina-foss/inaspeechsegmenter/blob/master/README.md Install inaSpeechSegmenter from its git repository. This includes cloning the repository, setting up a virtual environment, and installing dependencies using pip. ```bash git clone https://github.com/ina-foss/inaSpeechSegmenter.git python -m venv env source env/bin/activate cd inaSpeechSegmenter pip install . python setup.py test ``` -------------------------------- ### Install inaSpeechSegmenter Source: https://context7.com/ina-foss/inaspeechsegmenter/llms.txt Install the inaSpeechSegmenter toolkit and its prerequisites. Ensure ffmpeg is installed before proceeding with pip installation. ```bash # Prerequisites: ffmpeg sudo apt-get install ffmpeg # Install from PyPI (Python 3.8–3.13) pip install inaSpeechSegmenter # Or install from source git clone https://github.com/ina-foss/inaSpeechSegmenter.git cd inaSpeechSegmenter pip install . ``` -------------------------------- ### Install ffmpeg on Ubuntu Source: https://github.com/ina-foss/inaspeechsegmenter/blob/master/README.md Install ffmpeg on Ubuntu systems, which is a prerequisite for inaSpeechSegmenter to decode audio files. ```bash sudo apt-get install ffmpeg ``` -------------------------------- ### Install inaSpeechSegmenter via PIP Source: https://github.com/ina-foss/inaspeechsegmenter/blob/master/README.md Install the inaSpeechSegmenter framework and its dependencies using pip within a Python virtual environment. ```bash python -m venv env source env/bin/activate pip install inaSpeechSegmenter ``` -------------------------------- ### Install inaSpeechSegmenter Library Source: https://github.com/ina-foss/inaspeechsegmenter/blob/master/tutorials/Demo_INASPeechSegmenter.ipynb Installs the inaSpeechSegmenter Python library using pip. ```python # Install the library ! pip install inaSpeechSegmenter ``` -------------------------------- ### Get Help for ina_speech_segmenter.py Source: https://github.com/ina-foss/inaspeechsegmenter/blob/master/README.md Display the help message for the ina_speech_segmenter.py command-line tool to understand available options for segmentation. ```bash ina_speech_segmenter.py --help ``` -------------------------------- ### Start Pyro4 job dispatch server Source: https://context7.com/ina-foss/inaspeechsegmenter/llms.txt Start the Pyro4 server to dispatch jobs to connected clients. The server requires a hostname and a jobs CSV file. It will output a URI for clients to connect. ```bash # Start server (hostname must be reachable by clients) ina_speech_segmenter_pyro_server.py 192.168.1.10 jobs.csv # Output: Ready. Object uri = PYRO:obj_@192.168.1.10: ``` -------------------------------- ### Connect Pyro4 client with custom ffmpeg binary Source: https://context7.com/ina-foss/inaspeechsegmenter/llms.txt Connect a client to the Pyro4 server and specify a custom path to the ffmpeg binary. This is useful if ffmpeg is installed in a non-standard location. ```bash # Custom ffmpeg binary ina_speech_segmenter_pyro_client.py "PYRO:obj_@192.168.1.10:" --ffmpeg_binary /usr/local/bin/ffmpeg ``` -------------------------------- ### Start Pyro4 server and stop after dispatch Source: https://context7.com/ina-foss/inaspeechsegmenter/llms.txt Start the Pyro4 server and configure it to automatically stop after all jobs from the provided CSV file have been dispatched to clients. ```bash # Stop server automatically after all jobs are dispatched ina_speech_segmenter_pyro_server.py 192.168.1.10 jobs.csv --stop_after_dispatch ``` -------------------------------- ### Perform Segmentation Source: https://github.com/ina-foss/inaspeechsegmenter/blob/master/tutorials/API_Tutorial.ipynb Execute the segmentation process by calling the segmenter instance with the media file path. The result is a list of tuples, each representing a segment with its label, start time, and end time. ```python # segmentation is performed using the __call__ method of the segmenter instance segmentation = seg(media) ``` -------------------------------- ### Print Segmentation Results Source: https://github.com/ina-foss/inaspeechsegmenter/blob/master/tutorials/API_Tutorial.ipynb Display the segmentation results, which is a list of tuples. Each tuple contains a label ('male', 'female', 'music', 'noEnergy', 'noise'), the start time, and the end time of the segment. ```python # the result is a list of tuples # each tuple contains: # * label in 'male', 'female', 'music', 'noEnergy' # * start time of the segment # * end time of the segment print(segmentation) ``` -------------------------------- ### Segment a single media file Source: https://context7.com/ina-foss/inaspeechsegmenter/llms.txt Segment a local media file or a remote URL using the Segmenter. Optional start and stop times can be provided to process a specific time window. Results are returned as a list of (label, start_sec, stop_sec) tuples. ```python from inaSpeechSegmenter import Segmenter seg = Segmenter(vad_engine='smn', detect_gender=True) # Process a local file segmentation = seg('./media/musanmix.mp3') print(segmentation) # [('music', 0.0, 22.48), # ('noEnergy', 22.48, 29.08), # ('noise', 29.08, 52.8), # ('male', 63.34, 68.26), # ('male', 68.92, 71.6), ...] # Process only a time window (seconds 30 to 90) seg_slice = seg('./media/musanmix.mp3', start_sec=30.0, stop_sec=90.0) # Process a remote URL seg_url = seg('http://example.com/audio.mp3') # Process without gender detection seg_vad = Segmenter(detect_gender=False) result = seg_vad('./media/musanmix.mp3') # [('music', 0.0, 22.48), ('noise', 29.08, 52.8), ('speech', 63.34, 71.6), ...] ``` -------------------------------- ### Calculate Sequence Lengths Source: https://github.com/ina-foss/inaspeechsegmenter/blob/master/tutorials/Demo_INASPeechSegmenter.ipynb Adds a 'length' column to the DataFrame, calculating the duration of each segmented sequence by subtracting start time from stop time. ```python # Compute the length of each sequence df["length"] = df['stop'] - df['start'] ``` -------------------------------- ### Initialize Segmenter with different configurations Source: https://context7.com/ina-foss/inaspeechsegmenter/llms.txt Initialize the Segmenter engine with various configurations for VAD, gender detection, and GPU acceleration. Default settings include SMN VAD and gender detection. ```python from inaSpeechSegmenter import Segmenter # Default: smn VAD engine + gender detection enabled seg = Segmenter() # Speech/Music only (faster, no noise label, used in ICASSP 2018 / MIREX 2018) seg_sm = Segmenter(vad_engine='sm', detect_gender=True) # No gender classification (faster, outputs 'speech' instead of 'male'/'female') seg_no_gender = Segmenter(vad_engine='smn', detect_gender=False) # Large batch size for GPU acceleration seg_gpu = Segmenter( vad_engine='smn', detect_gender=True, ffmpeg='ffmpeg', # path to ffmpeg binary, or None to disable batch_size=1024, # default 32; larger = faster but more GPU memory energy_ratio=0.03 # fraction of mean energy used as activity threshold ) ``` -------------------------------- ### Initialize Speech Segmenter Source: https://github.com/ina-foss/inaspeechsegmenter/blob/master/tutorials/API_Tutorial.ipynb Create an instance of the Segmenter class. This step loads the neural networks and may take a few seconds. Warnings during this process do not affect the results. ```python # create an instance of speech segmenter # this loads neural networks and may last few seconds # Warnings have no incidence on the results seg = Segmenter() ``` -------------------------------- ### Segmenter.__init__ Source: https://context7.com/ina-foss/inaspeechsegmenter/llms.txt Initializes the segmentation engine by loading neural network models. It allows configuration of VAD engine, gender detection, ffmpeg path, GPU batch size, and energy threshold. ```APIDOC ## Segmenter.__init__ ### Description Loads the neural network models into memory. Accepts optional arguments to configure the VAD engine, gender detection, ffmpeg binary path, GPU batch size, and energy threshold. Must be instantiated before calling segmentation methods. ### Method `__init__` ### Parameters #### Optional Parameters - **vad_engine** (str) - Optional - Specifies the VAD engine to use (e.g., 'smn', 'sm'). - **detect_gender** (bool) - Optional - Whether to enable gender detection. Defaults to True. - **ffmpeg** (str) - Optional - Path to the ffmpeg binary. Set to None to disable. - **batch_size** (int) - Optional - GPU batch size for acceleration. Defaults to 32. - **energy_ratio** (float) - Optional - Fraction of mean energy used as activity threshold. Defaults to 0.03. ### Request Example ```python from inaSpeechSegmenter import Segmenter # Default initialization seg = Segmenter() # Initialization with specific configurations seg_sm = Segmenter(vad_engine='sm', detect_gender=True) seg_no_gender = Segmenter(vad_engine='smn', detect_gender=False) seg_gpu = Segmenter(vad_engine='smn', detect_gender=True, ffmpeg='ffmpeg', batch_size=1024, energy_ratio=0.03) ``` ``` -------------------------------- ### Connect a Pyro4 client to the server Source: https://context7.com/ina-foss/inaspeechsegmenter/llms.txt Connect a client to the Pyro4 server using the provided server URI. The client will fetch jobs and process them locally. Multiple clients can connect to process jobs in parallel. ```bash # Connect a GPU client to the server URI printed at server startup ina_speech_segmenter_pyro_client.py "PYRO:obj_@192.168.1.10:" ``` -------------------------------- ### Prepare jobs CSV for Pyro4 server Source: https://context7.com/ina-foss/inaspeechsegmenter/llms.txt Create a CSV file with 'source_path' and 'dest_path' columns to define the jobs for the Pyro4 server. This file specifies which audio files to process and where to save the results. ```bash cat > jobs.csv << EOF source_path,dest_path /data/audio/file1.mp3,/results/file1.csv /data/audio/file2.mp3,/results/file2.csv /data/audio/file3.wav,/results/file3.csv EOF ``` -------------------------------- ### Specify Media File Path Source: https://github.com/ina-foss/inaspeechsegmenter/blob/master/tutorials/API_Tutorial_VFS.ipynb Define the path to the audio file you want to analyze. Ensure the file is accessible. ```python fpath = "../media/0021.mp3" ``` ```python fpath = "../media/silence2sec.wav" ``` ```python fpath = "../media/lamartine.wav" ``` -------------------------------- ### VoiceFemininityScoring.__init__ — Initialize voice femininity scorer Source: https://context7.com/ina-foss/inaspeechsegmenter/llms.txt Initializes the voice femininity scorer by loading necessary models for gender detection and segmentation. Supports different model criteria for optimal performance. ```APIDOC ## VoiceFemininityScoring.__init__ ### Description Initializes the voice femininity scorer. Loads the VBx x-vector extractor (ONNX backend), a pre-trained MLP gender detection model, and an internal `Segmenter` for VAD. Two model criteria are available: `bgc` (best binary gender classification, default) and `vfp` (best voice femininity prediction on French CommonVoice). Designed for single-speaker recordings. ### Parameters - `gd_model_criteria` (str): Model criteria to use. Options are 'bgc' (default) or 'vfp'. - `backend` (str): The backend for the x-vector extractor. Currently supports 'onnx'. ### Usage ```python from inaSpeechSegmenter.vbx_segmenter import VoiceFemininityScoring # Default: BGC model (best overall binary gender classification) vfs = VoiceFemininityScoring(gd_model_criteria='bgc', backend='onnx') # VFP model (best voice femininity prediction, tuned for French CommonVoice) vfs_vfp = VoiceFemininityScoring(gd_model_criteria='vfp', backend='onnx') ``` ``` -------------------------------- ### Load Libraries for Segmentation and Analysis Source: https://github.com/ina-foss/inaspeechsegmenter/blob/master/tutorials/Demo_INASPeechSegmenter.ipynb Imports necessary libraries: Segmenter for audio processing, seg2csv for export, pandas for data manipulation, and seaborn for plotting. ```python # Load the libraries from inaSpeechSegmenter import Segmenter from inaSpeechSegmenter.export_funcs import seg2csv import pandas as pd import seaborn as sns ``` -------------------------------- ### Create VoiceFemininityScoring Instance Source: https://github.com/ina-foss/inaspeechsegmenter/blob/master/tutorials/API_Tutorial_VFS.ipynb Instantiate the VoiceFemininityScoring class. You can specify the gender detection model criteria ('bgc' or 'vfp'). 'bgc' is the default. ```python v = VoiceFemininityScoring(gd_model_criteria="vfp") ``` -------------------------------- ### Initialize VoiceFemininityScoring Source: https://context7.com/ina-foss/inaspeechsegmenter/llms.txt Loads the VBx x-vector extractor, a pre-trained MLP gender detection model, and an internal Segmenter for VAD. Two model criteria are available: 'bgc' (default) and 'vfp'. Designed for single-speaker recordings. ```python from inaSpeechSegmenter.vbx_segmenter import VoiceFemininityScoring # Default: BGC model (best overall binary gender classification) vfs = VoiceFemininityScoring(gd_model_criteria='bgc', backend='onnx') # VFP model (best voice femininity prediction, tuned for French CommonVoice) vfs_vfp = VoiceFemininityScoring(gd_model_criteria='vfp', backend='onnx') ``` -------------------------------- ### Run Audio Segmentation Source: https://github.com/ina-foss/inaspeechsegmenter/blob/master/tutorials/Demo_INASPeechSegmenter.ipynb Executes the segmentation process on the specified media file using the loaded Segmenter model. ```python # Run the segmentation segmentation = seg(media) ``` -------------------------------- ### Specify Media for Analysis Source: https://github.com/ina-foss/inaspeechsegmenter/blob/master/tutorials/API_Tutorial.ipynb Define the path to the media file (audio or video) that will be analyzed. Any format supported by ffmpeg can be used. ```python # select a media to analyse # any media supported by ffmpeg may be used (video, audio, urls) media = './media/musanmix.mp3' ``` -------------------------------- ### Import VoiceFemininityScoring Class Source: https://github.com/ina-foss/inaspeechsegmenter/blob/master/tutorials/API_Tutorial_VFS.ipynb Import the necessary class for voice femininity scoring from the inaSpeechSegmenter library. ```python from inaSpeechSegmenter.vbx_segmenter import VoiceFemininityScoring ``` -------------------------------- ### Load INA Speech Segmenter API Source: https://github.com/ina-foss/inaspeechsegmenter/blob/master/tutorials/API_Tutorial.ipynb Import the necessary classes from the inaSpeechSegmenter library to begin. ```python # Load the API from inaSpeechSegmenter import Segmenter from inaSpeechSegmenter.export_funcs import seg2csv, seg2textgrid ``` -------------------------------- ### Process audio from a remote URL Source: https://context7.com/ina-foss/inaspeechsegmenter/llms.txt Segment audio directly from a remote URL. Ensure the URL is accessible and points to a valid audio file. ```bash ina_speech_segmenter.py -i http://example.com/radio.mp3 -o /results/ ``` -------------------------------- ### Connect Pyro4 client with large batch size Source: https://context7.com/ina-foss/inaspeechsegmenter/llms.txt Connect a client to the Pyro4 server and specify a large batch size for processing. This optimizes throughput for GPU-accelerated clients. ```bash # Use a large batch size for faster GPU throughput ina_speech_segmenter_pyro_client.py "PYRO:obj_@192.168.1.10:" --batch_size 1024 ``` -------------------------------- ### Segment a list of specific audio files Source: https://context7.com/ina-foss/inaspeechsegmenter/llms.txt Provide a list of specific audio files as input. The tool will process each file individually and save the results to the output directory. ```bash ina_speech_segmenter.py -i /data/a.mp3 /data/b.wav /data/c.mp4 -o /results/ ``` -------------------------------- ### Segment audio files using glob patterns Source: https://context7.com/ina-foss/inaspeechsegmenter/llms.txt Use a glob pattern to specify multiple input audio files for segmentation. The output will be saved to the specified directory. ```bash ina_speech_segmenter.py -i "/data/audio/*.mp3" -o /results/ ``` -------------------------------- ### Process multiple media files in batch Source: https://context7.com/ina-foss/inaspeechsegmenter/llms.txt Process a list of input media files in batch mode, writing results to specified output paths. Supports CSV and Praat TextGrid formats, with options for progress verbosity, skipping existing files, retries, and delay between retries. ```python from inaSpeechSegmenter import Segmenter import os seg = Segmenter(batch_size=1024) input_files = [ './media/musanmix.mp3', './media/lamartine.wav', './media/0021.mp3', ] output_files = [ '/tmp/out/musanmix.csv', '/tmp/out/lamartine.csv', '/tmp/out/0021.csv', ] os.makedirs('/tmp/out', exist_ok=True) total_duration, nb_processed, avg_time, messages = seg.batch_process( linput=input_files, loutput=output_files, verbose=True, # print progress skipifexist=True, # skip if output file already exists nbtry=3, # retry count for remote/unstable files trydelay=2.0, # seconds to wait between retries output_format='csv' # 'csv' or 'textgrid' ) print(f"Processed {nb_processed} files in {total_duration:.1f}s (avg {avg_time:.2f}s/file)") # Each message is (output_path, status_code, status_string) ``` -------------------------------- ### Pull the official Docker image Source: https://context7.com/ina-foss/inaspeechsegmenter/llms.txt Download the latest official inaSpeechSegmenter Docker image from Docker Hub. This image contains all necessary dependencies for running the tool. ```bash # Pull the official Docker image docker pull inafoss/inaspeechsegmenter ``` -------------------------------- ### Initialize inaSpeechSegmenter Model Source: https://github.com/ina-foss/inaspeechsegmenter/blob/master/tutorials/Demo_INASPeechSegmenter.ipynb Loads the default inaSpeechSegmenter model for use in segmentation tasks. ```python # Load the model seg = Segmenter() ``` -------------------------------- ### Convert media to 16 kHz mono signal with media2sig16kmono Source: https://context7.com/ina-foss/inaspeechsegmenter/llms.txt Low-level utility using ffmpeg to decode audio/video formats into a 16 kHz mono NumPy float array. Supports optional time slicing and different data types. Can decode WAV without ffmpeg if it's already 16kHz mono. ```python from inaSpeechSegmenter.io import media2sig16kmono import numpy as np # Decode any format via ffmpeg (default) signal = media2sig16kmono('./media/musanmix.mp3') print(signal.shape, signal.dtype) # (N,) float64 # Decode a specific time slice signal_slice = media2sig16kmono('./media/musanmix.mp3', start_sec=10.0, stop_sec=30.0) # Decode as float32 (for neural network input) signal_f32 = media2sig16kmono('./media/lamartine.wav', dtype='float32') # Without ffmpeg (file must already be 16kHz mono WAV) signal_no_ffmpeg = media2sig16kmono('./media/lamartine.wav', ffmpeg=None, dtype='float64') # Raises AssertionError if sample rate != 16000 ``` -------------------------------- ### Compute and Print Voice Femininity Score Source: https://github.com/ina-foss/inaspeechsegmenter/blob/master/tutorials/API_Tutorial_VFS.ipynb Call the instantiated object with the file path to compute the voice femininity score, detected speech duration, and number of retained vectors. Print the results. ```python vf_score, speech_detected, nb_retained_vectors = v(fpath) print("Detected speech duration : %.2fs" % speech_detected) print("Voice femininity score : %.9f" % vf_score) ``` -------------------------------- ### Connect Pyro4 client disabling ffmpeg Source: https://context7.com/ina-foss/inaspeechsegmenter/llms.txt Connect a client to the Pyro4 server and disable ffmpeg. This requires input files to be pre-decoded into 16kHz mono WAV format. ```bash # Disable ffmpeg on client (pre-decoded 16kHz files) ina_speech_segmenter_pyro_client.py "PYRO:obj_@192.168.1.10:" --ffmpeg_binary None ``` -------------------------------- ### View TextGrid Output Source: https://github.com/ina-foss/inaspeechsegmenter/blob/master/tutorials/API_Tutorial.ipynb Display the content of the generated TextGrid file to verify the exported segmentation data in Praat format. ```bash !cat myseg.TextGrid ``` -------------------------------- ### Run segmentation inside Docker Source: https://context7.com/ina-foss/inaspeechsegmenter/llms.txt Execute ina_speech_segmenter.py within a Docker container. Mount local directories for audio input and results output. This ensures a consistent environment for segmentation. ```bash # Run segmentation inside Docker (mount local data) docker run --rm \ -v /local/audio:/data \ -v /local/results:/results \ inafoss/inaspeechsegmenter \ ina_speech_segmenter.py -i "/data/*.mp3" -o /results/ -s 1024 ``` -------------------------------- ### ina_speech_segmenter.py — CLI batch segmentation tool Source: https://context7.com/ina-foss/inaspeechsegmenter/llms.txt A command-line interface tool for batch processing audio files for speech segmentation. It supports various input formats and output options. ```APIDOC ## ina_speech_segmenter.py (CLI) ### Description Segments one or more media files from the command line and writes CSV or TextGrid output files to a specified directory. Supports glob patterns and HTTP URLs as input. ### Usage ```bash # Basic usage: segment a single file with default settings (smn VAD + gender) ina_speech_segmenter.py -i /path/to/audio.mp3 -o /path/to/output/ ``` ### Options - `-i` or `--input`: Input file path, directory, glob pattern, or HTTP URL. - `-o` or `--output`: Output directory for the segmentation files. - Other options may be available for specifying segmentation models, output formats, etc. (Refer to the tool's help message for details). ``` -------------------------------- ### Use 'sm' VAD engine Source: https://context7.com/ina-foss/inaspeechsegmenter/llms.txt Specify the 'sm' VAD engine for segmentation, which focuses on speech and music while excluding noise. This is useful for cleaner segmentation of relevant audio content. ```bash ina_speech_segmenter.py -i audio.mp3 -o /results/ -d sm ``` -------------------------------- ### CLI batch segmentation with ina_speech_segmenter.py Source: https://context7.com/ina-foss/inaspeechsegmenter/llms.txt Segments one or more media files from the command line and writes CSV or TextGrid output files to a specified directory. Supports glob patterns and HTTP URLs as input. ```bash # Basic usage: segment a single file with default settings (smn VAD + gender) ina_speech_segmenter.py -i /path/to/audio.mp3 -o /path/to/output/ ``` -------------------------------- ### Segmenter.batch_process Source: https://context7.com/ina-foss/inaspeechsegmenter/llms.txt Processes a list of input media files in batches, writing results to specified output paths. Supports CSV and Praat TextGrid formats and includes options for retries and skipping existing files. ```APIDOC ## Segmenter.batch_process ### Description Processes a list of input media files and writes results to corresponding output paths. Supports CSV and Praat TextGrid output formats. Uses background threading for I/O and GPU inference overlap. Returns timing and error statistics. ### Method `batch_process` ### Parameters #### Path Parameters - **linput** (list) - Required - A list of paths to the input media files. - **loutput** (list) - Required - A list of paths for the output files. #### Query Parameters - **verbose** (bool) - Optional - If True, prints progress information. Defaults to False. - **skipifexist** (bool) - Optional - If True, skips processing if the output file already exists. Defaults to False. - **nbtry** (int) - Optional - Number of retries for unstable files. Defaults to 3. - **trydelay** (float) - Optional - Delay in seconds between retries. Defaults to 2.0. - **output_format** (str) - Optional - The desired output format, either 'csv' or 'textgrid'. Defaults to 'csv'. ### Request Example ```python from inaSpeechSegmenter import Segmenter import os seg = Segmenter(batch_size=1024) input_files = [ './media/musanmix.mp3', './media/lamartine.wav', './media/0021.mp3', ] output_files = [ '/tmp/out/musanmix.csv', '/tmp/out/lamartine.csv', '/tmp/out/0021.csv', ] os.makedirs('/tmp/out', exist_ok=True) total_duration, nb_processed, avg_time, messages = seg.batch_process( linput=input_files, loutput=output_files, verbose=True, skipifexist=True, nbtry=3, trydelay=2.0, output_format='csv' ) print(f"Processed {nb_processed} files in {total_duration:.1f}s (avg {avg_time:.2f}s/file)") ``` ### Response #### Success Response (200) - **total_duration** (float) - Total processing time in seconds. - **nb_processed** (int) - Number of files successfully processed. - **avg_time** (float) - Average processing time per file in seconds. - **messages** (list) - A list of messages, where each message is a tuple `(output_path, status_code, status_string)` indicating the processing status for each file. ``` -------------------------------- ### Export segmentation to Praat TextGrid with seg2textgrid Source: https://context7.com/ina-foss/inaspeechsegmenter/llms.txt Converts a segmentation list to a Praat TextGrid file with a single tier named 'inaSpeechSegmenter'. Compatible with Praat for phonetic annotation and analysis. ```python from inaSpeechSegmenter import Segmenter from inaSpeechSegmenter.export_funcs import seg2textgrid seg = Segmenter() segmentation = seg('./media/musanmix.mp3') seg2textgrid(segmentation, 'output.TextGrid') ``` -------------------------------- ### Compute voice femininity score with VoiceFemininityScoring Source: https://context7.com/ina-foss/inaspeechsegmenter/llms.txt Processes an audio file through the VBx pipeline to compute a voice femininity score. Returns a tuple of (score, speech_duration, nb_retained_vectors). Score is None if no speech is detected. ```python from inaSpeechSegmenter.vbx_segmenter import VoiceFemininityScoring vfs = VoiceFemininityScoring(gd_model_criteria='vfp') # Score a file with a single speaker score, speech_duration, nb_vectors = vfs('./media/lamartine.wav') if score is not None: print(f"Detected speech: {speech_duration:.2f}s") print(f"Retained x-vectors: {nb_vectors}") print(f"Voice femininity score: {score:.9f}") # score ~1.0 → predicted female voice # score ~0.0 → predicted male voice # score ~0.55 → ambiguous / transition voice else: print("No speech detected in the recording.") ``` -------------------------------- ### Export segmentation to CSV with seg2csv Source: https://context7.com/ina-foss/inaspeechsegmenter/llms.txt Converts a segmentation list to a tab-separated CSV file compatible with Sonic Visualiser. If fout is None, the result is printed to stdout. ```python from inaSpeechSegmenter import Segmenter, seg2csv seg = Segmenter() segmentation = seg('./media/musanmix.mp3') # Write to a CSV file seg2csv(segmentation, 'output.csv') # Print to stdout (fout=None) seg2csv(segmentation, None) ``` -------------------------------- ### Custom energy ratio threshold Source: https://context7.com/ina-foss/inaspeechsegmenter/llms.txt Set a custom energy ratio threshold for segmentation. Adjusting this value can fine-tune the sensitivity of the speech detection. ```bash ina_speech_segmenter.py -i audio.mp3 -o /results/ -r 0.05 ``` -------------------------------- ### View CSV Output Source: https://github.com/ina-foss/inaspeechsegmenter/blob/master/tutorials/API_Tutorial.ipynb Display the content of the generated CSV file to verify the exported segmentation data. ```bash !cat myseg.csv ``` -------------------------------- ### Large batch size for GPU acceleration Source: https://context7.com/ina-foss/inaspeechsegmenter/llms.txt Set a large batch size for processing to leverage GPU acceleration. This can significantly speed up segmentation for large numbers of files. ```bash ina_speech_segmenter.py -i "*.mp3" -o /results/ -s 1024 ``` -------------------------------- ### Display Segmentation Results Source: https://github.com/ina-foss/inaspeechsegmenter/blob/master/tutorials/Demo_INASPeechSegmenter.ipynb Prints the segmentation results to the output. The 'segmentation' variable holds the outcome. ```python # Look at the outcome segmentation ``` -------------------------------- ### Export Segmentation to TextGrid Source: https://github.com/ina-foss/inaspeechsegmenter/blob/master/tutorials/API_Tutorial.ipynb Export the segmentation results to a Praat TextGrid file, a common format for phonetic and speech analysis. ```python # export to praat TextGrid is also supported seg2textgrid(segmentation, 'myseg.TextGrid') ``` -------------------------------- ### seg2textgrid — Export segmentation to Praat TextGrid Source: https://context7.com/ina-foss/inaspeechsegmenter/llms.txt Converts a segmentation list to a Praat TextGrid file with a single tier named `inaSpeechSegmenter`. Compatible with Praat for phonetic annotation and analysis. ```APIDOC ## seg2textgrid ### Description Converts a segmentation list to a Praat TextGrid file with a single tier named `inaSpeechSegmenter`. Compatible with [Praat](https://www.fon.hum.uva.nl/praat/) for phonetic annotation and analysis. ### Usage ```python from inaSpeechSegmenter import Segmenter from inaSpeechSegmenter.export_funcs import seg2textgrid seg = Segmenter() segmentation = seg('./media/musanmix.mp3') seg2textgrid(segmentation, 'output.TextGrid') ``` ### Example Output (TextGrid file content): ``` File type = "ooTextFile" Object class = "TextGrid" xmin = 0.000000 xmax = 74.500000 tiers? size = 1 item []: item [1]: class = "IntervalTier" name = "inaSpeechSegmenter" intervals[1]: xmin = 0.000000 xmax = 22.480000 text = "music" intervals[7]: xmin = 63.340000 xmax = 68.260000 text = "male" ... ``` ``` -------------------------------- ### Specify Media File for Segmentation Source: https://github.com/ina-foss/inaspeechsegmenter/blob/master/tutorials/Demo_INASPeechSegmenter.ipynb Defines the URL of the audio file (MP3 format) to be processed by the segmenter. ```python # Choose any mp3 file online media = 'https://github.com/ina-foss/inaSpeechSegmenter/raw/master/media/musanmix.mp3' ``` -------------------------------- ### Export segmentation to Praat TextGrid format Source: https://context7.com/ina-foss/inaspeechsegmenter/llms.txt Choose to export the segmentation results in Praat TextGrid format instead of the default CSV. This is useful for compatibility with Praat and Sonic Visualiser. ```bash ina_speech_segmenter.py -i audio.mp3 -o /results/ -e textgrid ``` -------------------------------- ### seg2csv — Export segmentation to CSV Source: https://context7.com/ina-foss/inaspeechsegmenter/llms.txt Converts a segmentation list to a tab-separated CSV file compatible with Sonic Visualiser. If `fout` is `None`, the result is printed to stdout. ```APIDOC ## seg2csv ### Description Converts a segmentation list to a tab-separated CSV file compatible with [Sonic Visualiser](https://www.sonicvisualiser.org). If `fout` is `None`, the result is printed to stdout. ### Usage ```python from inaSpeechSegmenter import Segmenter, seg2csv seg = Segmenter() segmentation = seg('./media/musanmix.mp3') # Write to a CSV file seg2csv(segmentation, 'output.csv') # Print to stdout (fout=None) seg2csv(segmentation, None) ``` ### Example Output (CSV file content): ``` labels start stop music 0.0 22.48 noEnergy 22.48 29.08 noise 29.08 52.8 male 63.34 68.26 ... ``` ``` -------------------------------- ### Aggregate Lengths by Label Source: https://github.com/ina-foss/inaspeechsegmenter/blob/master/tutorials/Demo_INASPeechSegmenter.ipynb Groups the DataFrame by 'labels' and calculates the sum of 'length' for each label, showing the total duration for music, noEnergy, male, and female segments. ```python # Compute the aggregated length of all sequences by label df[['labels', 'length']].groupby("labels").sum() ``` -------------------------------- ### Read Segmentation Results from CSV Source: https://github.com/ina-foss/inaspeechsegmenter/blob/master/tutorials/Demo_INASPeechSegmenter.ipynb Loads the 'myseg.csv' file into a pandas DataFrame for data analysis. ```python # Read the results in a table df = pd.read_table("myseg.csv") ``` -------------------------------- ### Disable ffmpeg for WAV input Source: https://context7.com/ina-foss/inaspeechsegmenter/llms.txt Disable the use of ffmpeg, requiring the input audio to be in 16kHz mono WAV format. This can be useful if ffmpeg is not available or if you are pre-processing audio. ```bash ina_speech_segmenter.py -i audio.wav -o /results/ -b None ``` -------------------------------- ### Export Segmentation Results to CSV Source: https://github.com/ina-foss/inaspeechsegmenter/blob/master/tutorials/Demo_INASPeechSegmenter.ipynb Saves the segmentation results to a CSV file named 'myseg.csv' for further analysis. ```python # Export results to CSV seg2csv(segmentation, 'myseg.csv') ``` -------------------------------- ### Segmenter.__call__ Source: https://context7.com/ina-foss/inaspeechsegmenter/llms.txt Segments a single media file (local or URL) and returns a list of (label, start_sec, stop_sec) tuples. Supports processing specific time slices. ```APIDOC ## Segmenter.__call__ ### Description Processes a single audio/video file (or URL) and returns a list of `(label, start_sec, stop_sec)` tuples. Labels are drawn from `{'male', 'female', 'speech', 'music', 'noise', 'noEnergy'}` depending on configuration. Accepts optional `start_sec` and `stop_sec` to process only a time slice. ### Method `__call__` ### Endpoint (This is a method call, not an HTTP endpoint) ### Parameters #### Path Parameters - **media_file** (str) - Required - Path to the local media file or a URL. #### Query Parameters - **start_sec** (float) - Optional - The starting time in seconds for processing. - **stop_sec** (float) - Optional - The ending time in seconds for processing. ### Request Example ```python from inaSpeechSegmenter import Segmenter seg = Segmenter(vad_engine='smn', detect_gender=True) # Process a local file segmentation = seg('./media/musanmix.mp3') print(segmentation) # Process only a time window (seconds 30 to 90) seg_slice = seg('./media/musanmix.mp3', start_sec=30.0, stop_sec=90.0) # Process a remote URL seg_url = seg('http://example.com/audio.mp3') # Process without gender detection seg_vad = Segmenter(detect_gender=False) result = seg_vad('./media/musanmix.mp3') ``` ### Response #### Success Response (200) - **segmentation** (list) - A list of tuples, where each tuple contains: - **label** (str) - The detected segment label (e.g., 'male', 'female', 'music', 'noise'). - **start_sec** (float) - The start time of the segment in seconds. - **stop_sec** (float) - The end time of the segment in seconds. ### Response Example ```json [ ('music', 0.0, 22.48), ('noEnergy', 22.48, 29.08), ('noise', 29.08, 52.8), ('male', 63.34, 68.26), ('male', 68.92, 71.6) ] ``` ``` -------------------------------- ### Generate Bar Plot of Segment Lengths Source: https://github.com/ina-foss/inaspeechsegmenter/blob/master/tutorials/Demo_INASPeechSegmenter.ipynb Creates a bar plot using seaborn to visualize the aggregated length of each label ('music', 'noEnergy', 'male', 'female'). ```python # Draw the plot sns.barplot( data = df_aggregated, x = "labels", y = "length" ) ``` -------------------------------- ### Export Segmentation to CSV Source: https://github.com/ina-foss/inaspeechsegmenter/blob/master/tutorials/API_Tutorial.ipynb Save the segmentation results to a CSV file. This file can be imported into visualization software like Sonic Visualiser. ```python # this writes the resulting segmentation into a csvfile # the csv file may be used to import segmentation into visualization softwares, # such as sonic-visualiser: https://www.sonicvisualiser.org seg2csv(segmentation, 'myseg.csv') ``` -------------------------------- ### Disable gender detection Source: https://context7.com/ina-foss/inaspeechsegmenter/llms.txt Disable gender detection to output 'speech' instead of 'male' or 'female' labels. This simplifies the output when gender information is not required. ```bash ina_speech_segmenter.py -i audio.mp3 -o /results/ -g false ``` -------------------------------- ### VoiceFemininityScoring.__call__ — Compute voice femininity score Source: https://context7.com/ina-foss/inaspeechsegmenter/llms.txt Computes the voice femininity score for an audio file by processing it through the VBx pipeline. Returns the score, speech duration, and number of retained vectors. ```APIDOC ## VoiceFemininityScoring.__call__ ### Description Processes a single audio file through the full VBx pipeline: mel band extraction → VAD → x-vector embedding → MLP gender prediction → femininity score aggregation. Returns a tuple of `(score, speech_duration, nb_retained_vectors)`. Score is `None` if no speech is detected. ### Parameters - `audio_path` (str): Path to the audio file to process. ### Returns - `score` (float or None): The voice femininity score. `None` if no speech is detected. - `speech_duration` (float): The duration of detected speech in seconds. - `nb_retained_vectors` (int): The number of x-vectors retained for scoring. ### Usage ```python from inaSpeechSegmenter.vbx_segmenter import VoiceFemininityScoring vfs = VoiceFemininityScoring(gd_model_criteria='vfp') # Score a file with a single speaker score, speech_duration, nb_vectors = vfs('./media/lamartine.wav') if score is not None: print(f"Detected speech: {speech_duration:.2f}s") print(f"Retained x-vectors: {nb_vectors}") print(f"Voice femininity score: {score:.9f}") # score ~1.0 → predicted female voice # score ~0.0 → predicted male voice # score ~0.55 → ambiguous / transition voice else: print("No speech detected in the recording.") ``` ### Example Output ``` Detected speech: 12.34s Retained x-vectors: 48 Voice femininity score: 0.550000000 ``` ``` -------------------------------- ### media2sig16kmono — Convert any media to 16 kHz mono signal Source: https://context7.com/ina-foss/inaspeechsegmenter/llms.txt A utility function that converts various media formats into a 16 kHz mono NumPy float array using ffmpeg. Supports optional time slicing and data type specification. ```APIDOC ## media2sig16kmono ### Description Low-level utility that uses ffmpeg to decode any audio/video format (or local 16 kHz WAV without ffmpeg) into a 16 kHz mono NumPy float array. Supports optional time slicing via `start_sec` and `stop_sec`. ### Parameters - `input_path` (str): Path to the input media file. - `start_sec` (float, optional): Start time in seconds for slicing. Defaults to `None`. - `stop_sec` (float, optional): Stop time in seconds for slicing. Defaults to `None`. - `dtype` (str, optional): Data type of the output NumPy array. Options include 'float64' (default) or 'float32'. - `ffmpeg` (str or None, optional): Path to the ffmpeg executable. If `None`, ffmpeg is not used (requires 16kHz mono WAV input). Defaults to `'ffmpeg'`. ### Returns - `signal` (np.ndarray): A 1D NumPy array representing the 16 kHz mono audio signal. ### Usage ```python from inaSpeechSegmenter.io import media2sig16kmono import numpy as np # Decode any format via ffmpeg (default) signal = media2sig16kmono('./media/musanmix.mp3') print(signal.shape, signal.dtype) # Example: (N,) float64 # Decode a specific time slice signal_slice = media2sig16kmono('./media/musanmix.mp3', start_sec=10.0, stop_sec=30.0) # Decode as float32 (for neural network input) signal_f32 = media2sig16kmono('./media/lamartine.wav', dtype='float32') # Without ffmpeg (file must already be 16kHz mono WAV) signal_no_ffmpeg = media2sig16kmono('./media/lamartine.wav', ffmpeg=None, dtype='float64') # Raises AssertionError if sample rate != 16000 ``` ``` -------------------------------- ### Store Aggregated Data Source: https://github.com/ina-foss/inaspeechsegmenter/blob/master/tutorials/Demo_INASPeechSegmenter.ipynb Creates a new DataFrame 'df_aggregated' containing the summed lengths for each label. ```python # Store the aggregated data in a new data frame df_aggregated= df[['labels', 'length']].groupby("labels").sum() ``` -------------------------------- ### Add Labels as a Column Source: https://github.com/ina-foss/inaspeechsegmenter/blob/master/tutorials/Demo_INASPeechSegmenter.ipynb Converts the index of the aggregated DataFrame (which contains the labels) into a regular column named 'labels'. ```python # Add the index as a column df_aggregated['labels'] = df_aggregated.index ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.