ru_tts

Форк
0
/
utterance.c 
217 строк · 6.5 Кб
1
/* utterance.c -- Utterance builder
2
 *
3
 * Copyright (C) 1990, 1991 Speech Research Laboratory, Minsk
4
 * Copyright (C) 2005 Igor Poretsky <poretsky@mlbox.ru>
5
 * Copyright (C) 2021 Boris Lobanov <lobbormef@gmail.com>
6
 * Copyright (C) 2021 Alexander Ivanov <ivalex01@gmail.com>
7
 *
8
 * SPDX-License-Identifier: MIT
9
 */
10

11
#include <stdint.h>
12
#include <stdlib.h>
13

14
#include "soundscript.h"
15
#include "transcription.h"
16

17

18
/* Local data */
19
static const uint8_t soundset1[] =
20
  {
21
    0, 0, 0, 0, 5, 5,
22
    5, 5, 0, 0, 0, 5,
23
    5, 5, 0, 0, 0, 5,
24
    5, 5, 0, 0, 0, 5,
25
    5, 5, 0, 5, 0, 0,
26
    0, 5, 5, 5, 0, 5
27
  };
28
static const uint8_t soundset2[] =
29
  {
30
    10, 20, 20, 20, 70, 50,
31
    60, 60, 40, 10, 20, 80,
32
    50, 60, 10, 20, 30, 50,
33
    60, 70, 10, 20, 30, 50,
34
    60, 70, 20, 60, 10, 20,
35
    20, 50, 60, 60, 30, 70
36
  };
37
static const uint8_t soundset3[] =
38
  {
39
    134, 134, 131,
40
    119, 119, 119
41
  };
42
static const uint8_t soundset4[] =
43
  {
44
    148, 148, 147,
45
    145, 145, 145
46
  };
47

48

49
/* Local subroutines */
50

51
/* Put specified sound into the soundscript */
52
static void put_sound(soundscript_t *script, uint8_t sound, uint8_t stage)
53
{
54
  script->sounds[script->length].id = sound;
55
  script->sounds[script->length++].stage = stage;
56
}
57

58

59
/* Global functions */
60

61
/* Build utterance according to phonetic transcription */
62
void build_utterance(uint8_t *transcription, soundscript_t *script)
63
{
64
  uint16_t i = TRANSCRIPTION_START;
65
  uint8_t a = 43;
66
  uint8_t c = transcription[i];
67

68
  while ((a < 44) && (i < TRANSCRIPTION_BUFFER_SIZE))
69
    {
70
      uint8_t flags = 0;
71
      uint16_t j;
72

73
      for (j = i; j < TRANSCRIPTION_BUFFER_SIZE; j++)
74
        if (transcription[j] != 43)
75
          {
76
            if (transcription[j] < 43)
77
              for (j++; j < TRANSCRIPTION_BUFFER_SIZE; j++)
78
                if (transcription[j] > 42)
79
                  {
80
                    if ((transcription[j] == 53) || (transcription[j] == 54))
81
                      flags |= 2;
82
                    break;
83
                  }
84
            break;
85
          }
86

87
      while (i < TRANSCRIPTION_BUFFER_SIZE)
88
        {
89
          uint8_t b = a;
90
          a = c;
91
          if (a > 43)
92
            break;
93
          flags &= ~1;
94

95
          while (i < TRANSCRIPTION_BUFFER_SIZE)
96
            {
97
              c = transcription[++i];
98
              if (c < 53)
99
                break;
100
              flags |= 1;
101
            }
102

103
          if (a == 43)
104
            {
105
              put_sound(script, 190, 2);
106
              break;
107
            }
108
          else if (a > 5)
109
            {
110
              if (a > 13)
111
                {
112
                  if (a > 19)
113
                    {
114
                      if (a > 31)
115
                        {
116
                          if (a > 41)
117
                            put_sound(script, 189, 2);
118
                          else if (a < 34)
119
                            {
120
                              put_sound(script, a + 143, 2);
121
                              put_sound(script, a + 145, 3);
122
                            }
123
                          else if ((a < 40) || (a == 41) || (c > 5))
124
                            put_sound(script, a + 145, 2);
125
                          else put_sound(script, a + soundset4[c], 2);
126
                        }
127
                      else
128
                        {
129
                          put_sound(script, a + 143, 2);
130
                          if (a < 29)
131
                            {
132
                              if (a < 26)
133
                                {
134
                                  if ((a < 23) && (c < 6))
135
                                    put_sound(script, a + soundset3[c], 3);
136
                                  else put_sound(script, a + 119, 3);
137
                                }
138
                              else if (c < 6)
139
                                put_sound(script, a + soundset3[c], 3);
140
                              else put_sound(script, a + 119, 3);
141
                            }
142
                          else put_sound(script, a + 119, 3);
143
                        }
144
                    }
145
                  else put_sound(script, a + 119, 2);
146
                }
147
              else
148
                {
149
                  if (b > 13)
150
                    put_sound(script, a + 99, 1);
151
                  if ((a != 10) || (transcription[i + 1] > 52) || ((c > 5) && (c < 44)))
152
                    {
153
                      put_sound(script, a + 117, 2);
154
                      if (c > 13)
155
                        put_sound(script, a + 99, 3);
156
                    }
157
                  else put_sound(script, 122, 2);
158
                }
159
            }
160
          else
161
            {
162
              j = 90;
163
              if (b > 5)
164
                {
165
                  if (b < 42)
166
                    j = soundset2[b - 6];
167
                  if (a == 5)
168
                    j--;
169
                }
170
              else j = (a != 5) ? 95 : 99;
171
              put_sound(script, a + j, 1);
172
              if (flags != 2)
173
                {
174
                  if ((b > 5) && (b < 42))
175
                    {
176
                      j = soundset1[b - 6];
177
                      if (a == 5)
178
                        j--;
179
                    }
180
                  else j = (a != 5) ? 0 : 4;
181
                  put_sound(script, a + j, 2);
182
                }
183
              if ((b > 5) && (b < 42))
184
                put_sound(script, a + soundset1[b - 6] + ((a != 5) ? 95 : 94), 3);
185
              else put_sound(script, a + ((a != 5) ? 95 : 99), 3);
186
              if (c > 5)
187
                {
188
                  if (c != 42)
189
                    {
190
                      if (c == 43)
191
                        {
192
                          j = transcription[i + 1];
193
                          if (j > 5)
194
                            {
195
                              if (j < 42)
196
                                put_sound(script, a + soundset2[j - 6] + ((a != 5) ? 5 : 4), 4);
197
                              else put_sound(script, a + ((a != 5) ? 90 : 89), 4);
198
                            }
199
                          else if (b > 5)
200
                            put_sound(script, a + ((a != 5) ? 95 : 99), 4);
201
                        }
202
                      else if (c > 43)
203
                        put_sound(script, a + ((a != 5) ? 90 : 89), 4);
204
                      else put_sound(script, a + soundset2[c - 6] + ((a != 5) ? 5 : 4), 4);
205
                    }
206
                  else put_sound(script, a + ((a != 5) ? 90 : 89), 4);
207
                }
208
              else if (b > 5)
209
                put_sound(script, a + ((a != 5) ? 95 : 99), 4);
210
            }
211
        }
212
    }
213

214
  if (i >= TRANSCRIPTION_BUFFER_SIZE)
215
    a = 44;
216
  put_sound(script, a + 147, 2);
217
}
218

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.