Mercurial > hg > auditok
comparison doc/examples.rst @ 385:edcc102fb33f
Update documentation and configuration
author | Amine Sehili <amine.sehili@gmail.com> |
---|---|
date | Tue, 02 Mar 2021 20:10:50 +0100 |
parents | df2a320e10d5 |
children | 81bc2375354f |
comparison
equal
deleted
inserted
replaced
383:c030134b7870 | 385:edcc102fb33f |
---|---|
1 Loading audio data | 1 Load audio data |
2 ------------------ | 2 --------------- |
3 | 3 |
4 Audio data is loaded with the :func:`load` function which can read from audio | 4 Audio data is loaded with the :func:`load` function which can read from audio |
5 files, the microphone or use raw audio data. | 5 files, the microphone or use raw audio data. |
6 | 6 |
7 From a file | 7 From a file |
8 =========== | 8 =========== |
9 | 9 |
10 If the first argument of :func:`load` is a string, it should be a path to an audio | 10 If the first argument of :func:`load` is a string, it should be a path to an |
11 file. | 11 audio file. |
12 | 12 |
13 .. code:: python | 13 .. code:: python |
14 | 14 |
15 import auditok | 15 import auditok |
16 region = auditok.load("audio.ogg") | 16 region = auditok.load("audio.ogg") |
17 | 17 |
18 If input file contains a raw (headerless) audio data, passing `audio_format="raw"` | 18 If input file contains raw (headerless) audio data, passing `audio_format="raw"` |
19 and other audio parameters (`sampling_rate`, `sample_width` and `channels`) is | 19 and other audio parameters (`sampling_rate`, `sample_width` and `channels`) is |
20 mandatory. In the following example we pass audio parameters with their short | 20 mandatory. In the following example we pass audio parameters with their short |
21 names: | 21 names: |
22 | 22 |
23 .. code:: python | 23 .. code:: python |
40 sw = 2 | 40 sw = 2 |
41 ch = 1 | 41 ch = 1 |
42 data = b"\0" * sr * sw * ch | 42 data = b"\0" * sr * sw * ch |
43 region = auditok.load(data, sr=sr, sw=sw, ch=ch) | 43 region = auditok.load(data, sr=sr, sw=sw, ch=ch) |
44 print(region) | 44 print(region) |
45 # alternatively you can use | |
46 #region = auditok.AudioRegion(data, sr, sw, ch) | |
45 | 47 |
46 output: | 48 output: |
47 | 49 |
48 .. code:: bash | 50 .. code:: bash |
49 | 51 |
72 | 74 |
73 | 75 |
74 Skip part of audio data | 76 Skip part of audio data |
75 ======================= | 77 ======================= |
76 | 78 |
77 If the `skip` parameter is > 0, :func:`load` will skip that leading amount of audio | 79 If the `skip` parameter is > 0, :func:`load` will skip that amount in seconds |
78 data: | 80 of leading audio data: |
79 | 81 |
80 .. code:: python | 82 .. code:: python |
81 | 83 |
82 import auditok | 84 import auditok |
83 region = auditok.load("audio.ogg", skip=2) # skip the first 2 seconds | 85 region = auditok.load("audio.ogg", skip=2) # skip the first 2 seconds |
84 | 86 |
85 This argument must be 0 when reading from the microphone. | 87 This argument must be 0 when reading data from the microphone. |
88 | |
89 | |
90 Limit the amount of read audio | |
91 ============================== | |
92 | |
93 If the `max_read` parameter is > 0, :func:`load` will read at most that amount | |
94 in seconds of audio data: | |
95 | |
96 .. code:: python | |
97 | |
98 import auditok | |
99 region = auditok.load("audio.ogg", max_read=5) | |
100 assert region.duration <= 5 | |
101 | |
102 This argument is mandatory when reading data from the microphone. | |
86 | 103 |
87 | 104 |
88 Basic split example | 105 Basic split example |
89 ------------------- | 106 ------------------- |
90 | 107 |
186 :func:`split` will continue reading audio data until you press ``Ctrl-C``. If | 203 :func:`split` will continue reading audio data until you press ``Ctrl-C``. If |
187 you want to read a specific amount of audio data, pass the desired number of | 204 you want to read a specific amount of audio data, pass the desired number of |
188 seconds with the `max_read` argument. | 205 seconds with the `max_read` argument. |
189 | 206 |
190 | 207 |
191 Accessing recorded data after split | 208 Access recorded data after split |
192 ----------------------------------- | 209 -------------------------------- |
193 | 210 |
194 Using a :class:`Recorder` object you can get hold of acquired audio data: | 211 Using a :class:`Recorder` object you can get hold of acquired audio data: |
195 | 212 |
196 | 213 |
197 .. code:: python | 214 .. code:: python |
360 region = auditok.load("audio.wav") | 377 region = auditok.load("audio.wav") |
361 samples = region.samples | 378 samples = region.samples |
362 assert len(samples) == region.channels | 379 assert len(samples) == region.channels |
363 | 380 |
364 | 381 |
365 If `numpy` is not installed you can use: | 382 If `numpy` is installed you can use: |
366 | 383 |
367 .. code:: python | 384 .. code:: python |
368 | 385 |
369 import numpy as np | 386 import numpy as np |
370 region = auditok.load("audio.wav") | 387 region = auditok.load("audio.wav") |