summaryrefslogtreecommitdiff
path: root/doc
diff options
context:
space:
mode:
authorMatthias Geier <Matthias.Geier@gmail.com>2018-08-22 12:01:13 +0200
committerMatthias Geier <Matthias.Geier@gmail.com>2018-08-22 12:10:37 +0200
commit361e8dbf1a2343f3d13a74a37432d99b5f460c35 (patch)
treebe8a7041b09b3f494db784c0ca7c9f4598fea683 /doc
parent6bc399853f1c43ad65c7126516eee005264dfb01 (diff)
DOC: Split documentation into several pages
Diffstat (limited to 'doc')
l---------doc/CONTRIBUTING.rst1
-rw-r--r--doc/api.rst44
-rw-r--r--doc/conf.py2
-rw-r--r--doc/examples.rst2
-rw-r--r--doc/index.rst75
-rw-r--r--doc/installation.rst85
-rw-r--r--doc/usage.rst181
-rw-r--r--doc/version-history.rst8
8 files changed, 328 insertions, 70 deletions
diff --git a/doc/CONTRIBUTING.rst b/doc/CONTRIBUTING.rst
new file mode 120000
index 0000000..798f2aa
--- /dev/null
+++ b/doc/CONTRIBUTING.rst
@@ -0,0 +1 @@
+../CONTRIBUTING.rst \ No newline at end of file
diff --git a/doc/api.rst b/doc/api.rst
new file mode 100644
index 0000000..dac0e84
--- /dev/null
+++ b/doc/api.rst
@@ -0,0 +1,44 @@
+API Documentation
+=================
+
+.. automodule:: sounddevice
+ :members:
+ :undoc-members:
+ :exclude-members: RawInputStream, RawOutputStream, RawStream,
+ InputStream, OutputStream, Stream,
+ CallbackFlags, CallbackStop, CallbackAbort,
+ PortAudioError, DeviceList,
+ AsioSettings, CoreAudioSettings, WasapiSettings
+
+.. autoclass:: Stream
+ :members:
+ :undoc-members:
+ :inherited-members:
+
+.. autoclass:: InputStream
+
+.. autoclass:: OutputStream
+
+.. autoclass:: RawStream
+ :members: read, write
+
+.. autoclass:: RawInputStream
+
+.. autoclass:: RawOutputStream
+
+.. autoclass:: DeviceList
+
+.. autoclass:: CallbackFlags
+ :members:
+
+.. autoclass:: CallbackStop
+
+.. autoclass:: CallbackAbort
+
+.. autoclass:: PortAudioError
+
+.. autoclass:: AsioSettings
+
+.. autoclass:: CoreAudioSettings
+
+.. autoclass:: WasapiSettings
diff --git a/doc/conf.py b/doc/conf.py
index d68eb43..612348b 100644
--- a/doc/conf.py
+++ b/doc/conf.py
@@ -111,7 +111,7 @@ exclude_patterns = ['_build']
# The reST default role (used for this markup: `text`) to use for all
# documents.
-#default_role = None
+default_role = 'any'
# If true, '()' will be appended to :func: etc. cross-reference text.
#add_function_parentheses = True
diff --git a/doc/examples.rst b/doc/examples.rst
index c7d9d6b..3f0eb16 100644
--- a/doc/examples.rst
+++ b/doc/examples.rst
@@ -1,5 +1,3 @@
-:orphan:
-
Example Programs
================
diff --git a/doc/index.rst b/doc/index.rst
index 74c6274..1f73c92 100644
--- a/doc/index.rst
+++ b/doc/index.rst
@@ -1,75 +1,16 @@
-.. default-role:: py:obj
-
.. include:: ../README.rst
-.. only:: html
-
- More Examples
- ^^^^^^^^^^^^^
-
- For more examples, have a look at the :doc:`examples`.
-
-.. include:: ../CONTRIBUTING.rst
-
-.. default-role:: any
-
-API Documentation
------------------
-
-.. automodule:: sounddevice
- :members:
- :undoc-members:
- :exclude-members: RawInputStream, RawOutputStream, RawStream,
- InputStream, OutputStream, Stream,
- CallbackFlags, CallbackStop, CallbackAbort,
- PortAudioError, DeviceList,
- AsioSettings, CoreAudioSettings, WasapiSettings
-
-.. autoclass:: Stream
- :members:
- :undoc-members:
- :inherited-members:
-
-.. autoclass:: InputStream
-
-.. autoclass:: OutputStream
-
-.. autoclass:: RawStream
- :members: read, write
+----
-.. autoclass:: RawInputStream
+.. toctree::
-.. autoclass:: RawOutputStream
-
-.. autoclass:: DeviceList
-
-.. autoclass:: CallbackFlags
- :members:
-
-.. autoclass:: CallbackStop
-
-.. autoclass:: CallbackAbort
-
-.. autoclass:: PortAudioError
-
-.. autoclass:: AsioSettings
-
-.. autoclass:: CoreAudioSettings
-
-.. autoclass:: WasapiSettings
+ installation
+ usage
+ examples
+ CONTRIBUTING
+ api
+ version-history
.. only:: html
- Index
- -----
-
:ref:`genindex`
-
-Version History
----------------
-
-.. default-role:: py:obj
-
-.. include:: ../NEWS.rst
-
-.. default-role::
diff --git a/doc/installation.rst b/doc/installation.rst
new file mode 100644
index 0000000..e30db29
--- /dev/null
+++ b/doc/installation.rst
@@ -0,0 +1,85 @@
+Installation
+============
+
+First of all, you'll need Python_.
+Any version where CFFI_ is supported should work.
+If you don't have Python installed yet, you should get one of the
+distributions which already include CFFI and NumPy_ (and many other useful
+things), e.g. Anaconda_ or WinPython_.
+
+.. only:: html
+
+ .. image:: https://anaconda.org/conda-forge/python-sounddevice/badges/version.svg
+ :target: https://anaconda.org/conda-forge/python-sounddevice
+
+If you are using the ``conda`` package manager (e.g. with Anaconda_ for
+Linux/macOS/Windows), you can install the ``sounddevice`` module from the
+``conda-forge`` channel::
+
+ conda install -c conda-forge python-sounddevice
+
+There are also packages for several other package managers:
+
+.. only:: html
+
+ .. image:: https://repology.org/badge/vertical-allrepos/python:sounddevice.svg
+ :target: https://repology.org/metapackage/python:sounddevice
+
+.. only:: latex
+
+ https://repology.org/metapackage/python:sounddevice
+
+If you are using Windows, you can alternatively install one of the packages
+provided at https://www.lfd.uci.edu/~gohlke/pythonlibs/#sounddevice.
+The PortAudio_ library is included in the package and you can get the rest
+of the dependencies on the same page.
+
+Note that some of the aforementioned packages may be out-of-date.
+You can always get the newest ``sounddevice`` release from PyPI_
+(using ``pip``).
+If you want to try the latest development version, have a look at the section
+about :doc:`CONTRIBUTING`.
+
+.. only:: html
+
+ .. image:: https://badge.fury.io/py/sounddevice.svg
+ :target: https://pypi.org/project/sounddevice/
+
+To install the latest release from PyPI, use::
+
+ python3 -m pip install sounddevice --user
+
+If you want to install it system-wide for all users (assuming you have the
+necessary rights), you can just drop the ``--user`` option.
+If you have installed the module already, you can use the ``--upgrade`` flag to
+get the newest release.
+
+To un-install, use::
+
+ python3 -m pip uninstall sounddevice
+
+If you install the ``sounddevice`` module with ``pip`` on macOS or Windows, the
+PortAudio_ library will be installed automagically.
+On other platforms, you might have to install PortAudio with your package
+manager (the package might be called ``libportaudio2`` or similar).
+
+You might also have to install CFFI_ (from a package called ``python3-cffi`` or
+similar).
+
+NumPy_ is only needed if you want to play back and record NumPy arrays.
+The classes `sounddevice.RawStream`, `sounddevice.RawInputStream` and
+`sounddevice.RawOutputStream` use plain Python buffer objects and don't need
+NumPy at all.
+If you need NumPy, you should install it with your package manager (from a
+package named ``python3-numpy`` or similar) or use a Python distribution that
+already includes NumPy (see above).
+You can also install NumPy with ``pip``, but depending on your platform, this
+might require a compiler and several additional libraries.
+
+.. _PortAudio: http://www.portaudio.com/
+.. _NumPy: http://www.numpy.org/
+.. _Python: https://www.python.org/
+.. _Anaconda: https://www.anaconda.com/download/
+.. _WinPython: http://winpython.github.io/
+.. _CFFI: http://cffi.readthedocs.io/
+.. _PyPI: https://pypi.org/project/sounddevice/
diff --git a/doc/usage.rst b/doc/usage.rst
new file mode 100644
index 0000000..37e49a6
--- /dev/null
+++ b/doc/usage.rst
@@ -0,0 +1,181 @@
+Usage
+=====
+
+First, import the module:
+
+.. code:: python
+
+ import sounddevice as sd
+
+Playback
+--------
+
+Assuming you have a NumPy array named ``myarray`` holding audio data with a
+sampling frequency of ``fs`` (in the most cases this will be 44100 or 48000
+frames per second), you can play it back with `sounddevice.play()`:
+
+.. code:: python
+
+ sd.play(myarray, fs)
+
+This function returns immediately but continues playing the audio signal in the
+background. You can stop playback with `sounddevice.stop()`:
+
+.. code:: python
+
+ sd.stop()
+
+If you know that you will use the same sampling frequency for a while, you can
+set it as default using `sounddevice.default.samplerate`:
+
+.. code:: python
+
+ sd.default.samplerate = fs
+
+After that, you can drop the *samplerate* argument:
+
+.. code:: python
+
+ sd.play(myarray)
+
+Recording
+---------
+
+To record audio data from your sound device into a NumPy array, use
+`sounddevice.rec()`:
+
+.. code:: python
+
+ duration = 10.5 # seconds
+ myrecording = sd.rec(int(duration * fs), samplerate=fs, channels=2)
+
+Again, for repeated use you can set defaults using `sounddevice.default`:
+
+.. code:: python
+
+ sd.default.samplerate = fs
+ sd.default.channels = 2
+
+After that, you can drop the additional arguments:
+
+.. code:: python
+
+ myrecording = sd.rec(int(duration * fs))
+
+This function also returns immediately but continues recording in the
+background. In the meantime, you can run other commands. If you want to check
+if the recording is finished, you should use `sounddevice.wait()`:
+
+.. code:: python
+
+ sd.wait()
+
+If the recording was already finished, this returns immediately; if not, it
+waits and returns as soon as the recording is finished.
+
+Alternatively, you could have used the *blocking* argument in the first place:
+
+.. code:: python
+
+ myrecording = sd.rec(duration * fs, blocking=True)
+
+By default, the recorded array has the data type ``'float32'`` (see
+`sounddevice.default.dtype`), but this can be changed with the *dtype* argument:
+
+.. code:: python
+
+ myrecording = sd.rec(duration * fs, dtype='float64')
+
+Simultaneous Playback and Recording
+-----------------------------------
+
+To play back an array and record at the same time, use `sounddevice.playrec()`:
+
+.. code:: python
+
+ myrecording = sd.playrec(myarray, fs, channels=2)
+
+The number of output channels is obtained from ``myarray``, but the number of
+input channels still has to be specified.
+
+Again, default values can be used:
+
+.. code:: python
+
+ sd.default.samplerate = fs
+ sd.default.channels = 2
+ myrecording = sd.playrec(myarray)
+
+In this case the number of output channels is still taken from ``myarray``
+(which may or may not have 2 channels), but the number of input channels is
+taken from `sounddevice.default.channels`.
+
+Device Selection
+----------------
+
+In many cases, the default input/output device(s) will be the one(s) you want,
+but it is of course possible to choose a different device.
+Use `sounddevice.query_devices()` to get a list of supported devices.
+The same list can be obtained from a terminal by typing the command ::
+
+ python3 -m sounddevice
+
+You can use the corresponding device ID to select a desired device by assigning
+to `sounddevice.default.device` or by passing it as *device* argument to
+`sounddevice.play()`, `sounddevice.Stream()` etc.
+
+Instead of the numerical device ID, you can also use a space-separated list of
+case-insensitive substrings of the device name (and the host API name, if
+needed). See `sounddevice.default.device` for details.
+
+.. code:: python
+
+ import sounddevice as sd
+ sd.default.samplerate = 44100
+ sd.default.device = 'digital output'
+ sd.play(myarray)
+
+Callback Streams
+----------------
+
+Callback "wire" with `sounddevice.Stream`:
+
+.. code:: python
+
+ import sounddevice as sd
+ duration = 5.5 # seconds
+
+ def callback(indata, outdata, frames, time, status):
+ if status:
+ print(status)
+ outdata[:] = indata
+
+ with sd.Stream(channels=2, callback=callback):
+ sd.sleep(int(duration * 1000))
+
+Same thing with `sounddevice.RawStream`:
+
+.. code:: python
+
+ import sounddevice as sd
+ duration = 5.5 # seconds
+
+ def callback(indata, outdata, frames, time, status):
+ if status:
+ print(status)
+ outdata[:] = indata
+
+ with sd.RawStream(channels=2, dtype='int24', callback=callback):
+ sd.sleep(int(duration * 1000))
+
+.. note:: We are using 24-bit samples here for no particular reason
+ (just because we can).
+
+Blocking Read/Write Streams
+---------------------------
+
+Instead of using a callback function, you can also use the blocking methods
+`sounddevice.Stream.read()` and `sounddevice.Stream.write()` (and of course the
+corresponding methods in `sounddevice.InputStream`, `sounddevice.OutputStream`,
+`sounddevice.RawStream`, `sounddevice.RawInputStream` and
+`sounddevice.RawOutputStream`).
diff --git a/doc/version-history.rst b/doc/version-history.rst
new file mode 100644
index 0000000..04c6953
--- /dev/null
+++ b/doc/version-history.rst
@@ -0,0 +1,8 @@
+Version History
+===============
+
+.. default-role:: py:obj
+
+.. include:: ../NEWS.rst
+
+.. default-role::