Skip to main content

No project description provided

Project description

Audio-File Extraction

About

Use this tool to segment (i.e., clip or slice), copy, and extract short-duration recordings, from long-duration WAV or FLAC files. Segmenting audio files into smaller parts can make recordings compatible for certain analytical workflows and allow for easier manipulation and sharing. Segment and extracting recordings based on a list of recording start times (date times) and a desired duration. This allows for applications such as the extraction of stratified audio samples, among others.

Types of Installation

  1. Download the python package:

    pip install sound-extraction

    a. After the installation you can use the following command to run the program or use --help to see the arguments list:

    sound-extraction -r "/path/to/original/audio/files" -o "/path/to/output/folder" -c "/path/to/csv/file" -s "site_name"

and then you can follow the instructions for the arguments mentioned below to run the program. Python-Package OR

  1. If you want to run the program thorugh Docker then follow the steps below: Docker OR

  2. If you want to run the program from the source files then follow the steps below: Source-File.

Note: You can use any one of the installation above to run the program.

Using Dockerfile

  1. Download the Docker application: Docker.

  2. Download Dockerfile and requirements.txt files: Docker-File and Requirements.

  3. Open the terminal and go to the directory where you have downloaded the Dockerfile and requirements.txt files. Run the following command:

    docker build -t sound-extraction . docker run sound-extraction

Setup (Windows)

Download Audio-File Extraction Files: Sound-File Extraction

python -m venv venv
venv\Scripts\Activate
pip install -r requirements.txt

If creating virtual environment gives us an error then open the Powershell with administrator and run the following command:

Set-ExecutionPolicy Unrestricted

Setup (Linux)

Download Audio-File Extraction Files: Sound-File Extraction

python -m venv venv
source venv/bin/activate
pip install -r requirements.txt

Test Files Usage

Download Test Files: Test Files

python sound_extraction.py -r "/path/to/original/audio/files" -o "/path/to/output/folder" -c "/path/to/csv/file" -s "site_name"

Usage

  1. Run sound_extraction.py to get the extracted audio files. You need to set the working directory where the downloaded files are located. Here is an example:

    python sound_extraction.py -r "/path/to/original/audio/files" -o "/path/to/output/folder" -c "/path/to/csv/file" -s "site_name"

Arguments and commands used are required to get the extraction of audio files according to the sample times. After entering the argument users will be asked to enter the custom sub-directory nameto store the extracted audio files. If you don't want to enter the custom name then just press Enter and it will extract the audio files in the same output directory mentioned in the argument.

  1. Run sound_extraction.py to get the sliced audio files which can handle around 192K sample rate. Here is an example:

    python sound_extraction.py -r "/path/to/original/audio/files" -o "/path/to/output/folder" -slice 10

Arguments and commands used are required to get the slicing of larger audio files into smaller audio files of your choice.

Arguments

Here's a complete list of all command line arguments:

-r, Path to original audio files (required). Need to make sure all the audio files are stored in a folder.
-o, Path to output folder (required). Program will create a folder for you with current time, name of site and extraction of duration to the specified path.
-c, Path to the CSV file with the following requirements: Header should include "sample file" and "category" columns. The "sample file" column should be in the format 20220608_170343, and the "category" column should contain categories such as "Nocturnal", etc.
-s, Prefix or the recording name, or ID, etc. This will be used to name the extracted audio files.
-d, Duration of the extracted audio file. Change the duration of the extracted audio files, if required. Default is 3 minutes.
-span, Span of the audio file. Extracted audio files will not span to 3 minutes if the original file is shorter.
-e, Extension of the audio file (.wav or .flac). If your original audio files are flac then you need to use ".wav". Default is flac.
-slice, Slice the audio file in smaller segments/chunks. Default is 10 seconds.

We can see the arguments list by using the following command:

python sound_extraction.py -h
  1. This is very basic version of the analysis of the workflow, you can adjust it to your needs.

  2. All the unusual files are handled and will show in console as a log message.

  3. Please open an issue if you have any questions or suggestions to add any features.

  4. I will keep on updating the code and making it more efficient.

Error Handling

  1. Log file will be created in the output folder with the name of sound_extraction_logs.txt which will show all the corrupted files which happened during the extraction process.

  2. This program will send the error message to the Sentry server to improve the user performace and to keep track of the errors which will be handled by myself.

Important Notes

  1. Try to have your original audio files in subfolder of root directory and once you provide path of root folder then code will search for all the files in all subfolders as well as in root folder.

  2. Original files should be in the format 20220611T202300.wav or 20220611T202300.flac. Sample files in CSV should be in the format 20220611_202300.wav or 20220611_202300.flac under the heading sampleFile. For instance,

    Sample Image

Changelog

  1. All the version changes are mentioned in the CHANGELOG.md file.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sound-extraction-1.1.2.tar.gz (8.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sound_extraction-1.1.2-py3-none-any.whl (9.4 kB view details)

Uploaded Python 3

File details

Details for the file sound-extraction-1.1.2.tar.gz.

File metadata

  • Download URL: sound-extraction-1.1.2.tar.gz
  • Upload date:
  • Size: 8.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.8.0

File hashes

Hashes for sound-extraction-1.1.2.tar.gz
Algorithm Hash digest
SHA256 05680e4f97314491ca5924b736e671ca2a64e660be5831b405141e0d94859ffc
MD5 6baa46bf427efaac03b515e01a2aa795
BLAKE2b-256 36d06fd952b4d6d0197310560d4daa2c2414499556285c54aa10f0b3deecb0cc

See more details on using hashes here.

File details

Details for the file sound_extraction-1.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for sound_extraction-1.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 490be07538d247a229e2712eeff068125019d42376f3ebf1216aaa22a0fe097b
MD5 9ca8ea3253c69e1359ca05eaf480c47d
BLAKE2b-256 c85ae579d0a03a08e8a5c6b1570ea89112a38a58eba5a343250ebcfca190ac9f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page