ru_tts

Форк
0
/
text2speech.c 
90 строк · 3.2 Кб
1
/* text2speech.c -- Full TTS transfer
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
#include <string.h>
14

15
#include "ru_tts.h"
16
#include "sink.h"
17
#include "timing.h"
18
#include "modulation.h"
19
#include "transcription.h"
20
#include "synth.h"
21

22

23
/* Common entry points */
24

25
/*
26
 * Initialize ru_tts configuration structure with the default values.
27
 */
28
RUTTS_EXPORT void ru_tts_config_init(ru_tts_conf_t *config)
29
{
30
  config->speech_rate = 100;
31
  config->voice_pitch = 100;
32
  config->intonation = 100;
33
  config->general_gap_factor = 100;
34
  config->comma_gap_factor = 100;
35
  config->dot_gap_factor = 100;
36
  config->semicolon_gap_factor = 100;
37
  config->colon_gap_factor = 100;
38
  config->question_gap_factor = 100;
39
  config->exclamation_gap_factor = 100;
40
  config->intonational_gap_factor = 100;
41
  config->flags = DEC_SEP_POINT | DEC_SEP_COMMA;
42
}
43

44
/*
45
 * Perform TTS transformation for specified text.
46
 *
47
 * The first argument points to a configuration structure.
48
 * The second argument points to a zero-terminated string to transfer.
49
 * This string must contain a Russian text in koi8-r.
50
 * The next two arguments specify a buffer that will be used
51
 * by the library for delivering produced wave data
52
 * chunk by chunk to the consumer specified by the fourth argument.
53
 * The next argument points to any additional user data passed to the consumer.
54
 *
55
 * The last argument points to a structure containing TTS parameters.
56
 */
57
RUTTS_EXPORT void ru_tts_transfer(const ru_tts_conf_t *config,
58
                                  const char *text, void *wave_buffer, size_t wave_buffer_size,
59
                                  ru_tts_callback consumer, void *user_data)
60
{
61
  uint8_t *transcription_buffer = malloc(TRANSCRIPTION_BUFFER_SIZE);
62

63
  if (transcription_buffer)
64
    {
65
      ttscb_t ttscb;
66
      sink_t transcription_consumer;
67

68
      /* Initialize data structures */
69
      sink_setup(&(ttscb.wave_consumer), wave_buffer, wave_buffer_size, consumer, user_data);
70
      sink_setup(&transcription_consumer, transcription_buffer, TRANSCRIPTION_MAXLEN, synth_function, &ttscb);
71
      ttscb.flags = config->flags;
72

73
      /* Adjust speech rate */
74
      timing_setup(&(ttscb.timing), config->speech_rate, config->general_gap_factor);
75
      adjust_gaplen(&(ttscb.timing), ',', config->comma_gap_factor);
76
      adjust_gaplen(&(ttscb.timing), '.', config->dot_gap_factor);
77
      adjust_gaplen(&(ttscb.timing), ';', config->semicolon_gap_factor);
78
      adjust_gaplen(&(ttscb.timing), ':', config->colon_gap_factor);
79
      adjust_gaplen(&(ttscb.timing), '?', config->question_gap_factor);
80
      adjust_gaplen(&(ttscb.timing), '!', config->exclamation_gap_factor);
81
      adjust_gaplen(&(ttscb.timing), '-', config->intonational_gap_factor);
82

83
      /* Adjust voice pitch and intonation */
84
      modulation_setup(&(ttscb.modulation), config->voice_pitch, config->intonation);
85

86
      /* Process text */
87
      process_text(text, &transcription_consumer);
88
      free(transcription_buffer);
89
    }
90
}
91

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

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

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

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