File: SpeechDispatcher.cpp

package info (click to toggle)
dasher 5.0.0~beta~repack2-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 70,872 kB
  • sloc: xml: 181,314; cpp: 70,860; java: 8,020; python: 3,579; makefile: 939; sh: 324; ansic: 223; perl: 71
file content (41 lines) | stat: -rw-r--r-- 864 bytes parent folder | download | duplicates (5)
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
// Inclusion in build system conditional on USE_SPEECHDISPATCHER
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include "Speech.h"

CSpeech::CSpeech() : m_speaker(NULL) {
}

CSpeech::~CSpeech() {
	if (m_speaker) spd_close(m_speaker);
}


bool CSpeech::Init() {
	if (m_speaker) return true;

	m_speaker = spd_open("dasher", NULL, NULL, SPD_MODE_SINGLE);

	return m_speaker != NULL;
}

void CSpeech::Speak(const std::string &strText, bool bInterrupt, const std::string &lang) {
	if (!Init()) {
		return;
	}
	if (!bInterrupt) {
		if (!lang.empty()) {
			// Speechd only accepts 2-letter language codes and
			// silently ignores anything else.
			std::string shortLang = lang.substr(0, 2);
			spd_set_language(m_speaker, shortLang.c_str());
		}
		if (!strText.empty()) {
			spd_say(m_speaker, SPD_TEXT, strText.c_str());
		}
	} else {
		spd_stop(m_speaker);
	}	
}