|
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 |
*/
|
|
28 |
|
|
29 |
#pragma once
|
|
30 |
#include "AudioData.h"
|
|
31 |
using namespace std;
|
|
32 |
using namespace hlrc_server;
|
|
33 |
#include "hlrc_server/phoneme.h"
|
|
34 |
#include "hlrc_server/soundchunk.h"
|
|
35 |
#include "hlrc_server/utterance.h"
|
|
36 |
#include "hlrc_server/ttsAction.h"
|
|
37 |
|
|
38 |
//converter from ros utterance
|
|
39 |
class UtteranceROS : public Utterance {
|
|
40 |
public:
|
|
41 |
UtteranceROS(ttsResultConstPtr ros_utterance){
|
|
42 |
//set text:
|
|
43 |
set_text(ros_utterance->utterance.text);
|
|
44 |
|
|
45 |
//convert soundchunk to audio data:
|
|
46 |
extract_audio_data(ros_utterance->utterance.audio);
|
|
47 |
|
|
48 |
//convert phonemes:
|
|
49 |
extract_phonemes(ros_utterance->utterance.phonemes);
|
|
50 |
}
|
|
51 |
|
|
52 |
~UtteranceROS(){};
|
|
53 |
|
|
54 |
void extract_audio_data(soundchunk sound_chunk){
|
|
55 |
//extract data:
|
|
56 |
unsigned int audio_len = sound_chunk.data.size();
|
|
57 |
char *audio_data_char = (char *)sound_chunk.data.data();
|
|
58 |
|
|
59 |
audio_data->samples.resize(audio_len);
|
|
60 |
audio_data->samples.assign(audio_data_char, audio_data_char+audio_len);
|
|
61 |
printf("audio samplesize is %d bytes\n",(unsigned int)audio_data->samples.size());
|
|
62 |
|
|
63 |
/*
|
|
64 |
* : data()
|
|
65 |
, samplecount(0)
|
|
66 |
, channels(0)
|
|
67 |
, rate(0)
|
|
68 |
, sample_type(0)
|
|
69 |
, endianess(0) {
|
|
70 |
|
|
71 |
}*/
|
|
72 |
|
|
73 |
//extract format:
|
|
74 |
audio_data->sample_signed = true;
|
|
75 |
switch (sound_chunk.sample_type){
|
|
76 |
case(soundchunk::SAMPLE_U8): audio_data->sample_signed = false; //and fall through:
|
|
77 |
case(soundchunk::SAMPLE_S8): audio_data->sample_bit = 8; break;
|
|
78 |
|
|
79 |
case(soundchunk::SAMPLE_U16): audio_data->sample_signed = false; //and fall through:
|
|
80 |
case(soundchunk::SAMPLE_S16): audio_data->sample_bit = 16; break;
|
|
81 |
|
|
82 |
case(soundchunk::SAMPLE_U24): audio_data->sample_signed = false; //and fall through:
|
|
83 |
case(soundchunk::SAMPLE_S24): audio_data->sample_bit = 24; break;
|
|
84 |
|
|
85 |
default:
|
|
86 |
printf("> invalid sample type %d in ROS SoundChunk! ignoring request!\n", sound_chunk.sample_type);
|
|
87 |
throw runtime_error("UtteranceROS::convert_audio_data() unsupported sample type in ros SoundChunk");
|
|
88 |
}
|
|
89 |
|
|
90 |
//bitrate
|
|
91 |
audio_data->sample_rate = sound_chunk.rate;
|
|
92 |
|
|
93 |
//endianness
|
|
94 |
if (sound_chunk.endianess == soundchunk::ENDIAN_LITTLE){
|
|
95 |
audio_data->sample_big_endian = false;
|
|
96 |
}else if (sound_chunk.endianess == soundchunk::ENDIAN_BIG){
|
|
97 |
audio_data->sample_big_endian = true;
|
|
98 |
}else{
|
|
99 |
printf("> invalid SoundChunk byte_format");
|
|
100 |
throw runtime_error("UtteranceROS::convert_audio_data() unsupported byte_format in ros SoundChunk");
|
|
101 |
}
|
|
102 |
|
|
103 |
//number of channels
|
|
104 |
audio_data->sample_channels = sound_chunk.channels;
|
|
105 |
|
|
106 |
printf("> new AudioData: %s\n",audio_data->to_string().c_str());
|
|
107 |
}
|
|
108 |
|
|
109 |
void extract_phonemes(utterance::_phonemes_type ros_phones){
|
|
110 |
//extract phoneme vector
|
|
111 |
phonemes_vector.clear();
|
|
112 |
for(auto it = ros_phones.begin(); it<ros_phones.end(); it++){
|
|
113 |
Utterance::symbol_duration_pair_t phoneme = make_pair(it->symbol, it->duration);
|
|
114 |
phonemes_vector.push_back(phoneme);
|
|
115 |
}
|
|
116 |
}
|
|
117 |
|
|
118 |
};
|
|
119 |
|