summaryrefslogtreecommitdiff
path: root/speech.c
blob: 48ba8263b4aca72c9faa8669bef9e63dc73a5591 (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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/* speechd simple client program
 * CVS revision: $Id: speech.c,v 1.1.1.1 2005-11-27 20:48:30 martin-s Exp $
 * Author: Tomas Cerha <cerha@brailcom.cz> */

#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <glib.h>
#include <stdarg.h>

#include <libspeechd.h>
#include "speech.h"

struct speech {
	int sockfd;
};

struct speech *
speech_new(void) {
	struct speech *this;
	int sockfd;

	sockfd = spd_init("map","main");
	if (sockfd == 0) 
		return NULL;
	this=g_new(struct speech,1);
	if (this) {
		this->sockfd=sockfd;
	}
	return this;
}

int 
speech_say(struct speech *this, char *text) {
	int err;

	err = spd_sayf(this->sockfd, 2, text);
	if (err != 1)
		return 1;
	return 0;
}

int
speech_sayf(struct speech *this, char *format, ...) {
	char buffer[8192];
	va_list ap;
	va_start(ap,format);
	vsnprintf(buffer, 8192, format, ap);
	return speech_say(this, buffer);
}

int 
speech_destroy(struct speech *this) {
	spd_close(this->sockfd);
	g_free(this);
	return 0;
}