Revision f150aab5 server/src/Utterance.cpp

View differences:

server/src/Utterance.cpp
1 1
/*
2
* This file is part of hlrc_server
3
*
4
* Copyright(c) sschulz <AT> techfak.uni-bielefeld.de
5
* http://opensource.cit-ec.de/projects/hlrc_server
6
*
7
* This file may be licensed under the terms of the
8
* GNU General Public License Version 3 (the ``GPL''),
9
* or (at your option) any later version.
10
*
11
* Software distributed under the License is distributed
12
* on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either
13
* express or implied. See the GPL for the specific language
14
* governing rights and limitations.
15
*
16
* You should have received a copy of the GPL along with this
17
* program. If not, go to http://www.gnu.org/licenses/gpl.html
18
* or write to the Free Software Foundation, Inc.,
19
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20
*
21
* The development of this software was supported by the
22
* Excellence Cluster EXC 277 Cognitive Interaction Technology.
23
* The Excellence Cluster EXC 277 is a grant of the Deutsche
24
* Forschungsgemeinschaft (DFG) in the context of the German
25
* Excellence Initiative.
26
*
27
*/
2
 * This file is part of hlrc_server
3
 *
4
 * Copyright(c) sschulz <AT> techfak.uni-bielefeld.de
5
 * http://opensource.cit-ec.de/projects/hlrc_server
6
 *
7
 * This file may be licensed under the terms of the
8
 * GNU General Public License Version 3 (the ``GPL''),
9
 * or (at your option) any later version.
10
 *
11
 * Software distributed under the License is distributed
12
 * on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either
13
 * express or implied. See the GPL for the specific language
14
 * governing rights and limitations.
15
 *
16
 * You should have received a copy of the GPL along with this
17
 * program. If not, go to http://www.gnu.org/licenses/gpl.html
18
 * or write to the Free Software Foundation, Inc.,
19
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20
 *
21
 * The development of this software was supported by the
22
 * Excellence Cluster EXC 277 Cognitive Interaction Technology.
23
 * The Excellence Cluster EXC 277 is a grant of the Deutsche
24
 * Forschungsgemeinschaft (DFG) in the context of the German
25
 * Excellence Initiative.
26
 *
27
 */
28 28

  
29 29
#include "Utterance.h"
30 30
using namespace std;
......
32 32

  
33 33
#define DEBUG_PRINT_PHONEMES 1
34 34

  
35
Utterance::Utterance(){
36
    playing = false;
37
    text = "UNINITIALISED UTTERANCE";
38
    audio_data = boost::shared_ptr<AudioData>(new AudioData());
35
Utterance::Utterance() {
36
	playing = false;
37
	text = "UNINITIALISED UTTERANCE";
38
	audio_data = boost::shared_ptr<AudioData>(new AudioData());
39 39
}
40 40

  
41
void Utterance::set_phoneme_vector(phonemes_vector_t p){
42
    phonemes_vector = p;
41
void Utterance::set_phoneme_vector(phonemes_vector_t p) {
42
	phonemes_vector = p;
43 43
}
44 44

  
45
void Utterance::set_text(string t){
46
    text = t;
45
void Utterance::set_text(string t) {
46
	text = t;
47 47
}
48 48

  
49
void Utterance::set_audio_data(boost::shared_ptr<AudioData> a){
50
    audio_data = a;
49
void Utterance::set_audio_data(boost::shared_ptr<AudioData> a) {
50
	audio_data = a;
51 51
}
52 52

  
53
Utterance::~Utterance(){
53
Utterance::~Utterance() {
54 54
}
55 55

  
56
string Utterance::get_text(){
57
    return text;
56
string Utterance::get_text() {
57
	return text;
58 58
}
59 59

  
60
boost::shared_ptr<AudioData> Utterance::get_audio_data(){
61
    return audio_data;
60
boost::shared_ptr<AudioData> Utterance::get_audio_data() {
61
	return audio_data;
62 62
}
63 63

  
64
void Utterance::start_playback(){
65
    if (phonemes_vector.size() == 0){
66
        printf("> we have an empty phoneme vector. not playing.\n");
67
        return;
68
    }
64
void Utterance::start_playback() {
65
	if (phonemes_vector.size() == 0) {
66
		printf("> we have an empty phoneme vector. not playing.\n");
67
		return;
68
	}
69 69

  
70
    //set iterator to start:
71
    phonemes_vector_iterator = phonemes_vector.begin();
70
	// set iterator to start:
71
	phonemes_vector_iterator = phonemes_vector.begin();
72 72

  
73
    //fetch first end time
74
    symbol_duration_pair_t symbol_duration_pair = *phonemes_vector_iterator;
75
    symbol_end_time = get_system_time() + boost::posix_time::milliseconds(symbol_duration_pair.second);
73
	// fetch first end time
74
	symbol_duration_pair_t symbol_duration_pair = *phonemes_vector_iterator;
75
	symbol_end_time = get_system_time() + boost::posix_time::milliseconds(symbol_duration_pair.second);
76 76

  
77
    printf("> we have %d pairs\n",(int)phonemes_vector.size());
77
	printf("> we have %d pairs\n", (int)phonemes_vector.size());
78 78

  
79
    //go!
80
    playing = true;
79
	// go!
80
	playing = true;
81 81
}
82 82

  
83
string Utterance::currently_active_phoneme(){
84
    //not active -> return
85
    if (!playing) return "";
86

  
87
    //empty phoneme list
88
    if (phonemes_vector.size() == 0) return "";
89

  
90
    system_time now = get_system_time();
91

  
92
    while(now > symbol_end_time){
93
        //fetch next phoneme:
94
        symbol_duration_pair_t symbol_duration_pair = *phonemes_vector_iterator;
95
        symbol_end_time = symbol_end_time + boost::posix_time::milliseconds(symbol_duration_pair.second);
96
        //printf("time: %d", symbol_duration_pair.second);
97

  
98
        //do we have to increment the iterator or are we done? (NOTE: -1 is necessary here!)
99
        if (phonemes_vector_iterator < phonemes_vector.end() - 1){
100
            phonemes_vector_iterator++;
101
        }else{
102
            //reached end, stop playback
103
            playing=false;
104
            return "";
105
            if (DEBUG_PRINT_PHONEMES) printf("\n");
106
        }
107
    }
108

  
109
    //fetch active symbol:
110
    string symbol = ((symbol_duration_pair_t)*phonemes_vector_iterator).first;
111
    //printf("> active symbol = %s\n",symbol.c_str());
112
    if (DEBUG_PRINT_PHONEMES) printf("%s ",symbol.c_str()); fflush(stdout);
113

  
114
    return symbol;
83
string Utterance::currently_active_phoneme() {
84
	// not active -> return
85
	if (!playing)
86
		return "";
87

  
88
	// empty phoneme list
89
	if (phonemes_vector.size() == 0)
90
		return "";
91

  
92
	system_time now = get_system_time();
93

  
94
	while (now > symbol_end_time) {
95
		// fetch next phoneme:
96
		symbol_duration_pair_t symbol_duration_pair = *phonemes_vector_iterator;
97
		symbol_end_time = symbol_end_time + boost::posix_time::milliseconds(symbol_duration_pair.second);
98
		// printf("time: %d", symbol_duration_pair.second);
99

  
100
		// do we have to increment the iterator or are we done? (NOTE: -1 is necessary here!)
101
		if (phonemes_vector_iterator < phonemes_vector.end() - 1) {
102
			phonemes_vector_iterator++;
103
		}
104
		else {
105
			// reached end, stop playback
106
			playing = false;
107
			return "";
108
			if (DEBUG_PRINT_PHONEMES)
109
				printf("\n");
110
		}
111
	}
112

  
113
	// fetch active symbol:
114
	string symbol = ((symbol_duration_pair_t)*phonemes_vector_iterator).first;
115
	// printf("> active symbol = %s\n",symbol.c_str());
116
	if (DEBUG_PRINT_PHONEMES)
117
		printf("%s ", symbol.c_str());
118
	fflush(stdout);
119

  
120
	return symbol;
115 121
}
116 122

  
117
bool Utterance::is_playing(){
118
    return playing;
123
bool Utterance::is_playing() {
124
	return playing;
119 125
}

Also available in: Unified diff