This page explains how you can incorporate the OpenVokaturi software in your own Python app.

The following example reads a WAV file from disk and analyzes its emotions, on the Mac. This example script is in a folder called examples, and next to this folder there is a folder api, which contains the module file, and a folder lib, which contains the library file

# Paul Boersma 2019-06-02
# A sample script that uses the OpenVokaturi library to extract the emotions from
# a wav file on disk. The file can contain a mono or stereo recording.
# Call syntax:
#   python3 path_to_sound_file.wav

import sys

import Vokaturi

print("Loading library...")
print("Analyzed by: %s" % Vokaturi.versionAndLicense())

print("Reading sound file...")
file_name = sys.argv[1]
(sample_rate, samples) =
print("   sample rate %.3f Hz" % sample_rate)

print("Allocating Vokaturi sample array...")
buffer_length = len(samples)
print("   %d samples, %d channels" % (buffer_length, samples.ndim))
c_buffer = Vokaturi.SampleArrayC(buffer_length)
if samples.ndim == 1:
    c_buffer[:] = samples[:] / 32768.0  # mono
    c_buffer[:] = 0.5*(samples[:,0]+0.0+samples[:,1]) / 32768.0  # stereo

print("Creating VokaturiVoice...")
voice = Vokaturi.Voice(sample_rate, buffer_length)

print("Filling VokaturiVoice with samples...")
voice.fill(buffer_length, c_buffer)

print("Extracting emotions from VokaturiVoice...")
quality = Vokaturi.Quality()
emotionProbabilities = Vokaturi.EmotionProbabilities()
voice.extract(quality, emotionProbabilities)

if quality.valid:
    print("Neutral: %.3f" % emotionProbabilities.neutrality)
    print("Happy: %.3f" % emotionProbabilities.happiness)
    print("Sad: %.3f" % emotionProbabilities.sadness)
    print("Angry: %.3f" % emotionProbabilities.anger)
    print("Fear: %.3f" % emotionProbabilities.fear)


The trick in this “batch” example is to create a Vokaturi.Voice that is big enough to contain all samples, then use Vokaturi.fill() only once, i.e. to transfer all the samples of the sound file into the Vokaturi.Voice object in one go. The analysis by Vokaturi.extract() will then report the emotions averaged over the whole file.

On Windows, you replace OpenVokaturi-3-3-mac64.dylib with OpenVokaturi-3-3-win32.dll or OpenVokaturi-3-3-win64.dll, and you may have to put libgcc_s_sjlj-1.dll in the same folder as your script. On 64-bit Linux, you replace OpenVokaturi-3-3-mac64.dylib with