aboutsummaryrefslogtreecommitdiffstats
path: root/src/n_speak.c
blob: a1266c7830f57cb92a2b7a5c1736672d1a097946 (plain)
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
/****************************************************************************************/
/*                                                                                      */
/*  File     : n_speak.c                                                  /_________/   */
/*  Author   : Joe                                                              |       */
/*  Date     : 04/2020                                                          |       */
/*  Info     : Uses espeak lib to speak                                         |       */
/*                                                                      /       |       */
/*                                                                      \       /       */
/*                                                                       \_____/        */
/*                                                                                      */
/****************************************************************************************/

#include <jo_n_speak.h>

void
n_speak(const char *msg)
{
	espeak_ERROR	err;
	int32_t			samplerate;

	samplerate = espeak_Initialize
		(AUDIO_OUTPUT_PLAYBACK,
		 500,
		 NULL,
		 0);
	if (samplerate == -1) {
		dprintf(2, "Failed to initialize espeak\n");
		exit(JO_RET_ESPEAK_FAILED);
	}
	espeak_SetVoiceByName(JO_ESPEAK_VOICE);
	err = espeak_Synth
		(msg,
		 strlen(msg) + 1,
		 0,
		 POS_CHARACTER,
		 0,
		 espeakCHARS_AUTO | espeakENDPAUSE,
		 NULL,
		 NULL);
	if (err != EE_OK) {
		dprintf(STDERR_FILENO, "espeak synth error\n");
	}
	espeak_Synchronize();
	espeak_Terminate();
}