Skip to content

Commit

Permalink
Merge pull request #251 from iver56/ij/docs
Browse files Browse the repository at this point in the history
Add I/O example and usage example in TimeMask page
  • Loading branch information
iver56 authored Jan 2, 2023
2 parents 48b4b57 + 4c4e092 commit f7d4b93
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 0 deletions.
25 changes: 25 additions & 0 deletions demo/generate_examples_for_doc.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,31 @@ def generate_example(self):
return sound, transformed_sound, sample_rate


@register
class TimeMaskExample(TransformUsageExample):
transform_class = TimeMask

def generate_example(self):
random.seed(345)
np.random.seed(345)
transform = TimeMask(
min_band_part=0.1,
max_band_part=0.15,
fade=True,
p=1.0,
)

sound, sample_rate = load_sound_file(
librosa.example("libri1"), sample_rate=16000
)

sound = sound[..., 0 : int(4.7 * sample_rate)]

transformed_sound = transform(sound, sample_rate)

return sound, transformed_sound, sample_rate


@register
class TimeStretchExample(TransformUsageExample):
transform_class = TimeStretch
Expand Down
Binary file added docs/waveform_transforms/TimeMask.webp
Binary file not shown.
Binary file added docs/waveform_transforms/TimeMask_input.flac
Binary file not shown.
Binary file not shown.
27 changes: 27 additions & 0 deletions docs/waveform_transforms/time_mask.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,33 @@ _Added in v0.7.0_
Make a randomly chosen part of the audio silent. Inspired by
[https://arxiv.org/pdf/1904.08779.pdf](https://arxiv.org/pdf/1904.08779.pdf)


## Input-output example

Here we silence a part of a speech recording.

![Input-output waveforms and spectrograms](TimeMask.webp)

| Input sound | Transformed sound |
|-------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------|
| <audio controls><source src="../TimeMask_input.flac" type="audio/flac"></audio> | <audio controls><source src="../TimeMask_transformed.flac" type="audio/flac"></audio> |


## Usage example

```python
from audiomentations import TimeMask

transform = TimeMask(
min_band_part=0.1,
max_band_part=0.15,
fade=True,
p=1.0,
)

augmented_sound = transform(my_waveform_ndarray, sample_rate=16000)
```

## TimeMask API

[`min_band_part`](#min_band_part){ #min_band_part }: `float` • range: [0.0, 1.0]
Expand Down

0 comments on commit f7d4b93

Please sign in to comment.