The Clarify Python Helper Library wraps the entire Clarify API in a Python 3.x / 2.7 Client class.
Project description
.. image:: https://travis-ci.org/Clarify/clarify_python.svg
:target: https://travis-ci.org/Clarify/clarify_python
===============================
Clarify Python (3.x and 2.7) Helper Library
===============================
Python 3.x and 2.7 helper library for the Clarify API
NB: Version 2.x of this library is _not_ compatible with version 1.x.
* Free software: MIT license
Installing
----------
.. code-block:: bash
$ pip install clarify_python
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
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 module, and initialize a Client object with your API key:
.. code-block:: python
from clarify_python import clarify
client = clarify.Client('my_api_key')
Loading Audio
^^^^^^^^^^^^^
Once you've initialized a Client object, you load a file like this:
.. code-block:: python
client.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
client.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 = client.search(query='dorothy')
results = result['item_results']
items = result['_links']['items']
index = 0
for item in items:
bundle = client.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 = client.search(query='dorothy')
search_terms = json.dumps(result['search_terms'])
item_results = json.dumps(result['item_results'])
bundleref = result['_links']['items'][0]['href']
bundle = client.get_bundle(bundleref)
tracksref = bundle['_links']['clarify:tracks']['href']
tracks = client.get_track_list(tracksref)['tracks']
mediaURL = tracks[0]['media_url']
Scripts
----------
You can retrieve all your data from Clarify by running the clarify_export script. This will fetch all bundles, tracks, metadata, and insights and write all the JSON to files on your local disk.
.. code-block:: bash
$ CLARIFY_API_KEY=your-key clarify_export output_folder
History (Change Log)
--------------------
See `HISTORY.rst <HISTORY.rst>`_
TODO
----
See `TODO.rst <TODO.rst>`_
History
-------
3.1.1 (2018-09-28)
* Added captions to clarify_export script
3.1.0 (2016-10-26)
* Added Python 2.7 support
3.0.2 (2016-04-27)
* Added clarify_export script
3.0.1 (2016-01-05)
* Maintenance
3.0.0 (2015-12-01)
++++++++++++++++++
* BREAKING CHANGE: client.bundle_list_map(func) The func is now called
with client as the first parameter.
* Added insight access methods.
* Support for requesting non-autorun insights (ex. transcripts and captions)
* Support for embedding insights when requesting bundles.
* Support for external_id when creating or updating bundles.
* Added behave tests.
* Added unittests.
2.0.0 (2015-04-18)
++++++++++++++++++
* All deprecated code removed.
1.1.1 (2015-04-18)
++++++++++++++++++
* Deprecated use of set_key() in favor of Client class.
1.1.0 (2015-03-08)
++++++++++++++++++
* Switched from http.client to urllib3.
* Eliminated support for setting HTTP debug level. Use Runscope.
1.0.4 (2015-03-08)
++++++++++++++++++
* Added get_item_hrefs() utility function.
* Utility function cleanup.
1.0.3 (2015-03-07)
++++++++++++++++++
* Fixed some encoding bugs.
1.0.2 (2015-03-07)
++++++++++++++++++
* Version increment to work around a PyPI bug. Identical to 1.0.1.
1.0.1 (2015-03-07)
++++++++++++++++++
* Version increment to work around a PyPI bug. Identical to 1.0.0.
1.0.0 (2015-03-07)
++++++++++++++++++
* Port of 1.0.1 python 2 code.
:target: https://travis-ci.org/Clarify/clarify_python
===============================
Clarify Python (3.x and 2.7) Helper Library
===============================
Python 3.x and 2.7 helper library for the Clarify API
NB: Version 2.x of this library is _not_ compatible with version 1.x.
* Free software: MIT license
Installing
----------
.. code-block:: bash
$ pip install clarify_python
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
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 module, and initialize a Client object with your API key:
.. code-block:: python
from clarify_python import clarify
client = clarify.Client('my_api_key')
Loading Audio
^^^^^^^^^^^^^
Once you've initialized a Client object, you load a file like this:
.. code-block:: python
client.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
client.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 = client.search(query='dorothy')
results = result['item_results']
items = result['_links']['items']
index = 0
for item in items:
bundle = client.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 = client.search(query='dorothy')
search_terms = json.dumps(result['search_terms'])
item_results = json.dumps(result['item_results'])
bundleref = result['_links']['items'][0]['href']
bundle = client.get_bundle(bundleref)
tracksref = bundle['_links']['clarify:tracks']['href']
tracks = client.get_track_list(tracksref)['tracks']
mediaURL = tracks[0]['media_url']
Scripts
----------
You can retrieve all your data from Clarify by running the clarify_export script. This will fetch all bundles, tracks, metadata, and insights and write all the JSON to files on your local disk.
.. code-block:: bash
$ CLARIFY_API_KEY=your-key clarify_export output_folder
History (Change Log)
--------------------
See `HISTORY.rst <HISTORY.rst>`_
TODO
----
See `TODO.rst <TODO.rst>`_
History
-------
3.1.1 (2018-09-28)
* Added captions to clarify_export script
3.1.0 (2016-10-26)
* Added Python 2.7 support
3.0.2 (2016-04-27)
* Added clarify_export script
3.0.1 (2016-01-05)
* Maintenance
3.0.0 (2015-12-01)
++++++++++++++++++
* BREAKING CHANGE: client.bundle_list_map(func) The func is now called
with client as the first parameter.
* Added insight access methods.
* Support for requesting non-autorun insights (ex. transcripts and captions)
* Support for embedding insights when requesting bundles.
* Support for external_id when creating or updating bundles.
* Added behave tests.
* Added unittests.
2.0.0 (2015-04-18)
++++++++++++++++++
* All deprecated code removed.
1.1.1 (2015-04-18)
++++++++++++++++++
* Deprecated use of set_key() in favor of Client class.
1.1.0 (2015-03-08)
++++++++++++++++++
* Switched from http.client to urllib3.
* Eliminated support for setting HTTP debug level. Use Runscope.
1.0.4 (2015-03-08)
++++++++++++++++++
* Added get_item_hrefs() utility function.
* Utility function cleanup.
1.0.3 (2015-03-07)
++++++++++++++++++
* Fixed some encoding bugs.
1.0.2 (2015-03-07)
++++++++++++++++++
* Version increment to work around a PyPI bug. Identical to 1.0.1.
1.0.1 (2015-03-07)
++++++++++++++++++
* Version increment to work around a PyPI bug. Identical to 1.0.0.
1.0.0 (2015-03-07)
++++++++++++++++++
* Port of 1.0.1 python 2 code.
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-3.1.1.tar.gz
(16.5 kB
view details)
File details
Details for the file clarify_python-3.1.1.tar.gz
.
File metadata
- Download URL: clarify_python-3.1.1.tar.gz
- Upload date:
- Size: 16.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: Python-urllib/3.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | da956cba901dddd340e369be825b1358066954f395b393ff14ef4dd8fd7536ff |
|
MD5 | 7b7f121ac1dcce96da3df62d589882a0 |
|
BLAKE2b-256 | 494846afb39fcddc8aa278b87ede9de7d977d9f2f6727733d06dc686b9baa8e0 |