You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- `Calibrate the recognizer energy threshold for ambient noise levels <https://github.com/Uberi/speech_recognition/blob/master/examples/calibrate_energy_threshold.py>`__ (see ``recognizer_instance.energy_threshold`` for details)
62
62
- `Listening to a microphone in the background <https://github.com/Uberi/speech_recognition/blob/master/examples/background_listening.py>`__
Copy file name to clipboardexpand all lines: reference/library-reference.rst
+25-10
Original file line number
Diff line number
Diff line change
@@ -42,29 +42,33 @@ To create a ``Microphone`` instance by name:
42
42
if microphone_name =="HDA Intel HDMI: 0 (hw:0,3)":
43
43
m = Microphone(i)
44
44
45
-
``WavFile(filename_or_fileobject)``
45
+
``AudioFile(filename_or_fileobject)``
46
46
-----------------------------------
47
47
48
-
Creates a new ``WavFile`` instance given a WAV audio file ``filename_or_fileobject``. Subclass of ``AudioSource``.
48
+
Creates a new ``AudioFile`` instance given a WAV/AIFF/FLAC audio file `filename_or_fileobject`. Subclass of ``AudioSource``.
49
49
50
-
If ``filename_or_fileobject`` is a string, then it is interpreted as a path to a WAV audio file (mono or stereo) on the filesystem. Otherwise, ``filename_or_fileobject`` should be a file-like object such as ``io.BytesIO`` or similar.
50
+
If ``filename_or_fileobject`` is a string, then it is interpreted as a path to an audio file on the filesystem. Otherwise, ``filename_or_fileobject`` should be a file-like object such as ``io.BytesIO`` or similar.
51
51
52
-
Note that using functions that read from the audio (such as ``recognizer_instance.record`` or ``recognizer_instance.listen``) will move ahead in the stream. For example, if you execute ``recognizer_instance.record(wavfile_instance, duration=10)`` twice, the first time it will return the first 10 seconds of audio, and the second time it will return the 10 seconds of audio right after that.
52
+
Note that functions that read from the audio (such as ``recognizer_instance.record`` or ``recognizer_instance.listen``) will move ahead in the stream. For example, if you execute ``recognizer_instance.record(audiofile_instance, duration=10)`` twice, the first time it will return the first 10 seconds of audio, and the second time it will return the 10 seconds of audio right after that. This is always reset when entering the context with a context manager.
53
53
54
-
Note that the WAV file must be in PCM/LPCM format; WAVE_FORMAT_EXTENSIBLE and compressed WAV are not supported and may result in undefined behaviour.
54
+
WAV files must be in PCM/LPCM format; WAVE_FORMAT_EXTENSIBLE and compressed WAV are not supported and may result in undefined behaviour.
55
+
56
+
Both AIFF and AIFF-C (compressed AIFF) formats are supported.
57
+
58
+
FLAC files must be in native FLAC format; OGG-FLAC is not supported and may result in undefined behaviour.
55
59
56
60
Instances of this class are context managers, and are designed to be used with ``with`` statements:
57
61
58
62
.. code:: python
59
63
60
64
import speech_recognition as sr
61
-
with sr.WavFile("SOMETHING.wav") as source: # open the WAV file for reading
62
-
pass# do things here - ``source`` is the WavFile instance created above
65
+
with sr.AudioFile("SOME_AUDIO_FILE") as source: # open the audio file for reading
66
+
pass# do things here - ``source`` is the AudioFile instance created above
63
67
64
-
``wavfile_instance.DURATION``
68
+
``audiofile_instance.DURATION``
65
69
-----------------------------
66
70
67
-
Represents the length of the audio stored in the WAV file in seconds. This property is only available when inside a context - essentially, that means it should only be accessed inside a ``with wavfile_instance ...`` statement. Outside of contexts, this property is ``None``.
71
+
Represents the length of the audio stored in the audio file in seconds. This property is only available when inside a context - essentially, that means it should only be accessed inside the body of a ``with audiofile_instance ...`` statement. Outside of contexts, this property is ``None``.
68
72
69
73
This is useful when combined with the ``offset`` parameter of ``recognizer_instance.record``, since when together it is possible to perform speech recognition in chunks.
70
74
@@ -248,7 +252,7 @@ Raises a ``speech_recognition.UnknownValueError`` exception if the speech is uni
248
252
249
253
Base class representing audio sources. Do not instantiate.
250
254
251
-
Instances of subclasses of this class, such as ``Microphone`` and ``WavFile``, can be passed to things like ``recognizer_instance.record`` and ``recognizer_instance.listen``.
255
+
Instances of subclasses of this class, such as ``Microphone`` and ``AudioFile``, can be passed to things like ``recognizer_instance.record`` and ``recognizer_instance.listen``.
252
256
253
257
``AudioData``
254
258
-------------
@@ -279,6 +283,17 @@ If ``convert_rate`` is specified and the audio sample rate is not ``convert_rate
279
283
280
284
Writing these bytes directly to a file results in a valid `WAV file <https://en.wikipedia.org/wiki/WAV>`__.
0 commit comments