hlrc / server / include / RSB / UtteranceRSB.h @ f27f1860
History | View | Annotate | Download (4.398 KB)
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 |
#include <rst/audition/SoundChunk.pb.h> |
32 |
#include <rst/audition/Utterance.pb.h> |
33 |
using namespace std; |
34 |
|
35 |
//converter from rsb utterance
|
36 |
class UtteranceRSB : public Utterance { |
37 |
public:
|
38 |
UtteranceRSB(rst::audition::Utterance rst_utterance){ |
39 |
//set text:
|
40 |
set_text(rst_utterance.textual_representation()); |
41 |
|
42 |
//convert soundchunk to audio data:
|
43 |
extract_audio_data(rst_utterance.audio()); |
44 |
|
45 |
//convert phonemes:
|
46 |
extract_phonemes(rst_utterance); |
47 |
} |
48 |
|
49 |
~UtteranceRSB(){}; |
50 |
|
51 |
void extract_audio_data(rst::audition::SoundChunk sound_chunk){
|
52 |
//cout << sound_chunk.DebugString();
|
53 |
|
54 |
//extract data:
|
55 |
unsigned int audio_len = sound_chunk.data().length(); |
56 |
char *audio_data_char = (char *)sound_chunk.data().c_str(); |
57 |
|
58 |
//audio.samples = vector<char>(audio_data_char, audio_data_char+audio_len);
|
59 |
audio_data->samples.resize(audio_len); |
60 |
audio_data->samples.assign(audio_data_char, audio_data_char+audio_len); |
61 |
|
62 |
printf("audio samplesize is %d bytes\n",(unsigned int)audio_data->samples.size()); |
63 |
|
64 |
//extract format:
|
65 |
audio_data->sample_signed = true;
|
66 |
switch (sound_chunk.sample_type()){
|
67 |
case(rst::audition::SoundChunk::SAMPLE_U8): audio_data->sample_signed = false; //and fall through: |
68 |
case(rst::audition::SoundChunk::SAMPLE_S8): audio_data->sample_bit = 8; break; |
69 |
|
70 |
case(rst::audition::SoundChunk::SAMPLE_U16): audio_data->sample_signed = false; //and fall through: |
71 |
case(rst::audition::SoundChunk::SAMPLE_S16): audio_data->sample_bit = 16; break; |
72 |
|
73 |
case(rst::audition::SoundChunk::SAMPLE_U24): audio_data->sample_signed = false; //and fall through: |
74 |
case(rst::audition::SoundChunk::SAMPLE_S24): audio_data->sample_bit = 24; break; |
75 |
|
76 |
default:
|
77 |
printf("> invalid sample type %d in RST SoundChunk! ignoring request!\n", sound_chunk.sample_type());
|
78 |
throw runtime_error("UtteranceRSB::convert_audio_data() unsupported sample type in rst::audition::SoundChunk");
|
79 |
} |
80 |
|
81 |
//bitrate
|
82 |
audio_data->sample_rate = sound_chunk.rate(); |
83 |
|
84 |
//endianness
|
85 |
if (sound_chunk.endianness() == rst::audition::SoundChunk::ENDIAN_LITTLE){
|
86 |
audio_data->sample_big_endian = false;
|
87 |
}else if (sound_chunk.endianness() == rst::audition::SoundChunk::ENDIAN_BIG){ |
88 |
audio_data->sample_big_endian = true;
|
89 |
}else{
|
90 |
printf("> invalid SoundChunk byte_format");
|
91 |
throw runtime_error("UtteranceRSB::convert_audio_data() unsupported byte_format in rst::audition::SoundChunk");
|
92 |
} |
93 |
|
94 |
//number of channels
|
95 |
audio_data->sample_channels = sound_chunk.channels(); |
96 |
|
97 |
printf("> new AudioData: %s\n",audio_data->to_string().c_str());
|
98 |
} |
99 |
|
100 |
void extract_phonemes(rst::audition::Utterance rst_utterance){
|
101 |
//extract phoneme vector
|
102 |
phonemes_vector.clear(); |
103 |
for(int i=0; i<rst_utterance.phonemes().element().size(); i++){ |
104 |
rst::audition::Phoneme rst_phoneme = rst_utterance.phonemes().element().Get(i); |
105 |
Utterance::symbol_duration_pair_t phoneme = make_pair(rst_phoneme.symbol(), rst_phoneme.duration()); |
106 |
phonemes_vector.push_back(phoneme); |
107 |
} |
108 |
} |
109 |
}; |
110 |
|