Python

Installation

After getting an API key, make sure to have pip and python3 installed.

For streaming purposes, portaudio need to be installed.

On Ubuntu

$ sudo apt install python-dev portaudio19-dev

On Mac

$ brew install portaudio

At the moment, we don’t support pip. Download our python library. Then unzip the file in the root of your project.

Then go in your root folder and run the following command:

$ pip install --no-cache-dir -r requirements.txt

Example – Audio file as input

If you want to analyze an audio file, you could use the code below.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
import json
from common.sense import sense
import pprint

apikey = 'Your API-key here'
filename = 'path/to/event/file.wav'
file_format = 'wav'
task = 'event'

result = sense(filename,apikey,file_format,task)
result = json.loads(result.outputs)
pprint.pprint(result)

Copy and paste that snippet of code in one of your python file. You will need to modify apikey, filename, file_format, and task variables.

  • apikey is the API key that you received via email. If you don’t have an API key, you can get an API key here
  • filename is the path to the file you want to analyze.
  • file_format is the format of the sound file you want to send.
  • task can take one of the following values :
'event'
'speech' #SUPPORTS INCOMING
'music' #SUPPORTS INCOMING

Example – Audio stream as input

If you want to send a stream i.e. from your microphone, you could use the code below.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
import json
import pprint

from common.sense import SenseStreamer
from common.sense import sense_stream_request
from common.sense import sense_stream_response

apikey = 'Your API-key here'
task = 'event'

with SenseStreamer(task) as stream:
    audio_generator = stream.generator()
    requests = sense_stream_request(audio_generator,apikey,task)
    responses = sense_stream_response(requests)

    for i in responses:
        pprint.pprint(i.outputs)

Copy and paste that snippet of code in one of your python file. You will need to modify apikey and task variables.

  • apikey is the API key that you received via email. If you don’t have an API key, you can get an API key here
  • task can take one of the following values :
'event'
'speech' #SUPPORTS INCOMING
'music' #SUPPORTS INCOMING