Speect C API

C code posted by jal
created at 26 May 14:12

Edit | Back
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
int main()
{
  s_erc error = S_SUCCESS;
  SUtterance *utt;
  SRelation *rel;
  SItem *item;
  SItem *item_daughter;


  /*
   * initialize speect
   */
  error = speect_init(NULL);
  if (error != S_SUCCESS)
  {
    printf("Failed to initialize Speect\n");
    return 1;
  }

  /* Create a new utterance */
  utt = (SUtterance*)S_NEW("SUtterance", &error);
  if (S_CHK_ERR(&error, S_CONTERR,
          "main",
          "Failed to create new utterance"))
    goto quit;

  /* initialize utterance */
  SUtteranceInit(&utt, NULL, &error);
  if (S_CHK_ERR(&error, S_CONTERR,
          "main",
          "Failed to initialize new utterance"))
    goto quit;

  /* Create a new relation */
  rel = (SRelation*)S_NEW("SRelation", &error);
  if (S_CHK_ERR(&error, S_CONTERR,
          "main",
          "Failed to create new relation"))
    goto quit;

  /* initialize relation */
  SRelationInit(&rel, "Word", &error);
  if (S_CHK_ERR(&error, S_CONTERR,
          "main",
          "Failed to initialize new relation"))
    goto quit;

  /* create an item, NULL shared contents */
  item = SRelationAppend(rel, NULL, &error);

  /* delete the relation using S_FORCE_DELETE, as the relation is
   * not connected to an utterance
   */
  S_FORCE_DELETE(rel, "main", &error);
  if (S_CHK_ERR(&error, S_CONTERR,
          "main",
          "Failed to delete new relation"))
    goto quit;

  /* Create a new relation */
  rel = (SRelation*)S_NEW("SRelation", &error);
  if (S_CHK_ERR(&error, S_CONTERR,
          "main",
          "Failed to create new relation"))
    goto quit;

  /* initialize relation */
  SRelationInit(&rel, "Word", &error);
  if (S_CHK_ERR(&error, S_CONTERR,
          "main",
          "Failed to initialize new relation"))
    goto quit;

  /* create an item, NULL shared contents */
  item = SRelationAppend(rel, NULL, &error);
  if (S_CHK_ERR(&error, S_CONTERR,
          "main",
          "Failed to create new appended item"))
    goto quit;

  /* connect relation to utterance */
  SUtteranceSetRelation(utt, rel, &error);
  if (S_CHK_ERR(&error, S_CONTERR,
          "main",
          "Failed to connect new relation to utterance"))
    goto quit;
  else
    rel = NULL; /* clear reference so that "goto quit" works */

  /* add daughter item */
  item_daughter = SItemAddDaughter(item, NULL, &error);
  if (S_CHK_ERR(&error, S_CONTERR,
          "main",
          "Failed to create new daughter item"))
    goto quit;

  /* Create a new relation with SUtteranceNewRelation */
  rel = SUtteranceNewRelation(utt, "Syllable", &error);
  if (S_CHK_ERR(&error, S_CONTERR,
          "main",
          "Failed to create new relation"))
    goto quit;

  /* create an item, NULL shared contents */
  item = SRelationAppend(rel, item_daughter, &error);
  rel = NULL; /* relation is connected to utterance */
  if (S_CHK_ERR(&error, S_CONTERR,
          "main",
          "Failed to create new appended item"))
    goto quit;

quit:
  /*
   * utterance will delete the
   * relation which in turn will
   * delete it's items.
   */
  if (utt != NULL)
    S_DELETE(utt, "main", &error);

  if (rel != NULL)
    S_FORCE_DELETE(rel, "main", &error);

  /*
   * quit speect
   */
  error = speect_quit();
  if (error != S_SUCCESS)
  {
    printf("Call to 'speect_quit' failed\n");
    return 1;
  }

  return 0;
}
3.18 KB in 5 ms with coderay