This section explains how to use AGLIB with a C++ example.
The following is example C++ code that uses AGLIB:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
#include <iostream> #include <set> #include <ag/AGAPI.h> using namespace std; int main() { AGSetId agsetId = CreateAGSet("TIMIT"); TimelineId timelineId = CreateTimeline(agsetId); SignalId signalId2 = CreateSignal(timelineId, "LDC93S1:train/dr1/fjsp0/sa1.wav", "audio", "wav", "wav", "16kHz", "2"); set<SignalId> signalIds; signalIds.insert(signalId2); AGId agId = CreateAG(agsetId, timelineId); SetFeature(agId, "Purpose", "Testing"); |
Line 3
You have to include AGAPI.h to use AGAPI functions.
Line 8
Create an AG set with "TIMIT" as its ID.
Line 10
Add a timeline to the TIMIT AGSet.
Lines 12-18
Add a signal to annotate to the timeline. The signal is located in
LDC93S1:train/dr1/fjsp0/sa1.wav, its MIME class is audio,
MIME type is wav, encoding is wav, sampling rate (unit) is
16kHz, and the channel we are interested in is 2.
Lines 19-20
Make a signal set with the signal we just created. We will annotate
this signal set later.
Lines 22-23
Create an AG and associate the timeline with it. Put some metadata on it:
Purpose=Testing.
24 25 26 27 28 29 30 31 32 33 34 35 |
AnchorId anchor1 = CreateAnchor(agId, 10, "sec", signalIds); AnchorId anchor2 = CreateAnchor(agId, 20, "sec", signalIds); AnchorId anchor3 = CreateAnchor(agId, 30, "sec", signalIds); AnnotationId annotation1 = CreateAnnotation(agId, anchor1, anchor2, "sentence"); AnnotationId annotation2 = CreateAnnotation(agId, anchor2, anchor3, "sentence"); SetFeature(annotation1,"label","He will walk to the store."); SetFeature(annotation2,"label","He will be walking."); cout << toXML(agsetId); } |
Lines 24-26
Create anchors on the signal set.
Lines 28-29
Create sentence annotations.
Lines 31-32
Put labels on the annotations.
NOTE: Please don't forget to set LD_LIBRARY_PATH properly for the other required shared libraries (libag and plugins). See Post-installation for details.