1 Star 0 Fork 0

yangliuly1 / auditok

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT
doc/figures/auditok-logo.png https://travis-ci.org/amsehili/auditok.svg?branch=master Documentation Status

auditok is an Audio Activity Detection tool that can process online data (read from an audio device or from standard input) as well as audio files. It can be used as a command line program or by calling its API.

A basic version of auditok will run with standard Python (>=3.4). Without installing additional dependencies, auditok can only deal with audio files in wav or raw formats. if you want more features, the following packages are needed:

  • pydub : read audio files in popular audio formats (ogg, mp3, etc.) or extract audio from a video file.
  • pyaudio : read audio data from the microphone and play back detections.
  • tqdm : show progress bar while playing audio clips.
  • matplotlib : plot audio signal and detections.
  • numpy : required by matplotlib. Also used for some math operations instead of standard python if available.

Installation

pip install git+https://github.com/amsehili/auditok

Basic example

from auditok import split

# split returns a generator of AudioRegion objects
audio_regions = split("audio.wav")
for region in audio_regions:
    region.play(progress_bar=True)
    filename = region.save("/tmp/region_{meta.start:.3f}.wav")
    print("region saved as: {}".format(filename))

Example using AudioRegion

from auditok import AudioRegion
region = AudioRegion.load("audio.wav")
regions = region.split_and_plot() # or just region.splitp()

output figure:

doc/figures/example_1.png

Working with AudioRegions

Beyond splitting, there are a couple of interesting operations you can do with AudioRegion objects.

Concatenate regions

from auditok import AudioRegion
region_1 = AudioRegion.load("audio_1.wav")
region_2 = AudioRegion.load("audio_2.wav")
region_3 = region_1 + region_2

Particularly useful if you want to join regions returned by split:

from auditok import AudioRegion
regions = AudioRegion.load("audio.wav").split()
gapless_region = sum(regions)

Repeat a region

Multiply by a positive integer:

from auditok import AudioRegion
region = AudioRegion.load("audio.wav")
region_x3 = region * 3

Make slices of equal size out of a region

Divide by a positive integer:

from auditok import AudioRegion
region = AudioRegion.load("audio.wav")
regions = regions / 5
assert sum(regions) == region

Make audio slices of arbitrary size

Slicing an AudioRegion can be interesting in many situations. You can for example remove a fixed-size portion of audio data from the beginning or the end of a region or crop a region by an arbitrary amount as a data augmentation strategy, etc.

The most accurate way to slice an AudioRegion is to use indices that directly refer to raw audio samples. In the following example, assuming that the sampling rate of audio data is 16000, you can extract a 5-second region from main region, starting from the 20th second as follows:

from auditok import AudioRegion
region = AudioRegion.load("audio.wav")
start = 20 * 16000
stop = 25 * 16000
five_second_region = region[start:stop]

This allows you to practically start and stop at any sample within the region. Just as with a list you can omit one of start and stop, or both. You can also use negative indices:

from auditok import AudioRegion
region = AudioRegion.load("audio.wav")
start = -3 * region.sr # `sr` is an alias of `sampling_rate`
three_last_seconds = region[start:]

While slicing by raw samples is accurate, slicing with temporal indices is more intuitive. You can do so by accessing the millis or seconds views of AudioRegion (or their shortcut alias ms and sec/s).

With the millis view:

from auditok import AudioRegion
region = AudioRegion.load("audio.wav")
five_second_region = region.millis[5000:10000]

or with the seconds view

from auditok import AudioRegion
region = AudioRegion.load("audio.wav")
five_second_region = region.seconds[5:10]

Get an array of audio samples

from auditok import AudioRegion
region = AudioRegion.load("audio.wav")
samples = region.samples

If numpy is installed, this will return a numpy.ndarray. If audio data is mono the returned array is 1D, otherwise it's 2D. If numpy is not installed this will return a standard array.array for mono data, and a list of array.array for multichannel data.

Alternatively you can use:

import numpy as np
region = AudioRegion.load("audio.wav")
samples = np.asarray(region)

License

MIT.

MIT License Copyright (c) 2019 Mohamed El Amine SEHILI Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

暂无描述 展开 收起
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
1
https://gitee.com/yang1y/auditok.git
git@gitee.com:yang1y/auditok.git
yang1y
auditok
auditok
master

搜索帮助