The Clarify Python 2 Helper Library wraps the entire Clarify API in Python 2.x function calls.
Project description
===============================
Clarify Python 2 Helper Library
===============================
Python 2.x helper library for the Clarify API
* Free software: MIT license
Installing
----------
.. code-block:: bash
$ pip install clarify_python_2
You may need to use sudo if you don't have permission to install.
Upgrading
---------
If you are running an older version of the python helper library, please upgrade.
.. code-block:: bash
$ pip install --upgrade clarify_python_2
You may need to use sudo if you don't have permission to upgrade.
Quickstart Guide
----------------
Getting Started
^^^^^^^^^^^^^^^
This quickstart demonstrates a simple way to get started using the Clarify API. Following these steps, it should take you no more than 5-10 minutes to have a fully functional search for your audio.
Configuring Your Environment
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
While you can use any programming language you choose, we provide helping libraries in a few to get you started. In Python, you simply include the Clarify file from the python_2 module, and initialize the environment with your API key:
.. code-block:: python
from clarify_python_2 import clarify
clarify.set_key('my api key')
Loading Audio
^^^^^^^^^^^^^
Once you've initialied the environment with your API key, you load a file like this:
.. code-block:: python
clarify.create_bundle(name='test bundle', media_url='http://example.com/sample-audio-file.wav')
Naming the bundle is optional.
Here are some audio files you can use for testing:
::
http://media.clarify.io/audio/samples/harvard-sentences-1.wav
http://media.clarify.io/audio/samples/harvard-sentences-2.wav
http://media.clarify.io/audio/books/dorothyandthewizardinoz_01_baum_64kb.mp3
Hint: You don't have to download these files. Instead you can pass us these urls via the create_bundle() method shown above.
Searching Audio
^^^^^^^^^^^^^^^
To search, we'll use the search() function. If you uploaded the *Wizard of Oz* audio clip, you can search for "dorothy":
.. code-block:: python
clarify.search(query='dorothy')
Then you can process and interact the results however you wish. The code below simply shows the resulting bundle id, bundle name, and the start/end offsets for each occurrence of the search terms. This assumes that the audio clip has been indexed by the time you search. If it hasn't, wait and try again in a few minutes.
.. code-block:: python
result = clarify.search(query='dorothy')
results = result['item_results']
items = result['_links']['items']
index = 0
for item in items:
bundle = clarify.get_bundle(item['href'])
print bundle['name']
search_hits = results[index]['term_results'][0]['matches'][0]['hits']
for search_hit in search_hits:
print str(search_hit['start']) + ' -- ' + str(search_hit['end'])
++index
And here are the results using the *Wizard of Oz* clip we loaded.
::
dorothy and her friends
2.35 -- 2.59
172.49 -- 172.83
224.82 -- 225.08
271.49 -- 271.8
329.1 -- 329.31
480.45 -- 480.92
Putting it all Together
^^^^^^^^^^^^^^^^^^^^^^^
From here, we can visualize our search results with the included audio player. The player should work with no additional configuration, but the bulk of the logic is here:
.. code-block:: python
import json
result = clarify.search(query='dorothy')
search_terms = json.dumps(result['search_terms'])
item_results = json.dumps(result['item_results'])
bundleref = result['_links']['items'][0]['href']
bundle = clarify.get_bundle(bundleref)
tracksref = bundle['_links']['clarify:tracks']['href']
tracks = clarify.get_track_list(tracksref)['tracks']
mediaURL = tracks[0]['media_url']
History (Change Log)
--------------------
See `HISTORY.rst <HISTORY.rst>`_
TODO
----
See `TODO.rst <TODO.rst>`_
History
-------
1.0.0 (2014-08-26)
++++++++++++++++++
* Updated to the 1.0 API.
* NB: The semantics of delete_track() have changed. delete_track() now takes an href to a track. To delte a track by index you now need to call delete_track_at_index().
0.9.0 (2014-06-16)
++++++++++++++++++
* Removed 'source' attribute from bundle.
0.8.0 (2014-05-04)
++++++++++++++++++
* Simplified initialization (and removed threading restriction).
* Separated REST cover and object libraries.
* Moved configuration variables into module's __init__.py file.
0.7.0 (2014-04-30)
++++++++++++++++++
* New repo name.
0.3.0 (2014-04-26)
++++++++++++++++++
* Code cleanup.
* get_bundle_href() changed to get_self_href().
* Switched to new style classes.
0.1.0 (2014-04-20)
++++++++++++++++++
* First release.
Clarify Python 2 Helper Library
===============================
Python 2.x helper library for the Clarify API
* Free software: MIT license
Installing
----------
.. code-block:: bash
$ pip install clarify_python_2
You may need to use sudo if you don't have permission to install.
Upgrading
---------
If you are running an older version of the python helper library, please upgrade.
.. code-block:: bash
$ pip install --upgrade clarify_python_2
You may need to use sudo if you don't have permission to upgrade.
Quickstart Guide
----------------
Getting Started
^^^^^^^^^^^^^^^
This quickstart demonstrates a simple way to get started using the Clarify API. Following these steps, it should take you no more than 5-10 minutes to have a fully functional search for your audio.
Configuring Your Environment
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
While you can use any programming language you choose, we provide helping libraries in a few to get you started. In Python, you simply include the Clarify file from the python_2 module, and initialize the environment with your API key:
.. code-block:: python
from clarify_python_2 import clarify
clarify.set_key('my api key')
Loading Audio
^^^^^^^^^^^^^
Once you've initialied the environment with your API key, you load a file like this:
.. code-block:: python
clarify.create_bundle(name='test bundle', media_url='http://example.com/sample-audio-file.wav')
Naming the bundle is optional.
Here are some audio files you can use for testing:
::
http://media.clarify.io/audio/samples/harvard-sentences-1.wav
http://media.clarify.io/audio/samples/harvard-sentences-2.wav
http://media.clarify.io/audio/books/dorothyandthewizardinoz_01_baum_64kb.mp3
Hint: You don't have to download these files. Instead you can pass us these urls via the create_bundle() method shown above.
Searching Audio
^^^^^^^^^^^^^^^
To search, we'll use the search() function. If you uploaded the *Wizard of Oz* audio clip, you can search for "dorothy":
.. code-block:: python
clarify.search(query='dorothy')
Then you can process and interact the results however you wish. The code below simply shows the resulting bundle id, bundle name, and the start/end offsets for each occurrence of the search terms. This assumes that the audio clip has been indexed by the time you search. If it hasn't, wait and try again in a few minutes.
.. code-block:: python
result = clarify.search(query='dorothy')
results = result['item_results']
items = result['_links']['items']
index = 0
for item in items:
bundle = clarify.get_bundle(item['href'])
print bundle['name']
search_hits = results[index]['term_results'][0]['matches'][0]['hits']
for search_hit in search_hits:
print str(search_hit['start']) + ' -- ' + str(search_hit['end'])
++index
And here are the results using the *Wizard of Oz* clip we loaded.
::
dorothy and her friends
2.35 -- 2.59
172.49 -- 172.83
224.82 -- 225.08
271.49 -- 271.8
329.1 -- 329.31
480.45 -- 480.92
Putting it all Together
^^^^^^^^^^^^^^^^^^^^^^^
From here, we can visualize our search results with the included audio player. The player should work with no additional configuration, but the bulk of the logic is here:
.. code-block:: python
import json
result = clarify.search(query='dorothy')
search_terms = json.dumps(result['search_terms'])
item_results = json.dumps(result['item_results'])
bundleref = result['_links']['items'][0]['href']
bundle = clarify.get_bundle(bundleref)
tracksref = bundle['_links']['clarify:tracks']['href']
tracks = clarify.get_track_list(tracksref)['tracks']
mediaURL = tracks[0]['media_url']
History (Change Log)
--------------------
See `HISTORY.rst <HISTORY.rst>`_
TODO
----
See `TODO.rst <TODO.rst>`_
History
-------
1.0.0 (2014-08-26)
++++++++++++++++++
* Updated to the 1.0 API.
* NB: The semantics of delete_track() have changed. delete_track() now takes an href to a track. To delte a track by index you now need to call delete_track_at_index().
0.9.0 (2014-06-16)
++++++++++++++++++
* Removed 'source' attribute from bundle.
0.8.0 (2014-05-04)
++++++++++++++++++
* Simplified initialization (and removed threading restriction).
* Separated REST cover and object libraries.
* Moved configuration variables into module's __init__.py file.
0.7.0 (2014-04-30)
++++++++++++++++++
* New repo name.
0.3.0 (2014-04-26)
++++++++++++++++++
* Code cleanup.
* get_bundle_href() changed to get_self_href().
* Switched to new style classes.
0.1.0 (2014-04-20)
++++++++++++++++++
* First release.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
clarify_python_2-1.0.1.tar.gz
(10.2 kB
view details)
Built Distribution
File details
Details for the file clarify_python_2-1.0.1.tar.gz
.
File metadata
- Download URL: clarify_python_2-1.0.1.tar.gz
- Upload date:
- Size: 10.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f5faca800a37824a1c4363b1a4934c71c5ca29923e9f555ad132b14ea4953f11 |
|
MD5 | 48f1f0cd507d044f8c2f2854e5ba22da |
|
BLAKE2b-256 | 05fe3bb75fc9e0b4e8461409b16e93470519e991915c68873516d0505863a0ee |
File details
Details for the file clarify_python_2-1.0.1.macosx-10.10-intel.exe
.
File metadata
- Download URL: clarify_python_2-1.0.1.macosx-10.10-intel.exe
- Upload date:
- Size: 76.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ea256ec751a4567e8d6aec9716740b6cf09b7c43da0befd762e609f5ac43f078 |
|
MD5 | 0f059c098658ae2ec39a35f8f21fd980 |
|
BLAKE2b-256 | b09ee4ba6e29355b31199aae4d0c3d4ea139af4d387474f4f5c886dd56e37f63 |