hlrc / server / include / RSB / UtteranceRSB.h @ 340bb7ae
History | View | Annotate | Download (4.01 KB)
1 | 0c286af0 | Simon Schulz | /*
|
---|---|---|---|
2 | f150aab5 | Robert Haschke | * 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 | 0c286af0 | Simon Schulz | |
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 | f150aab5 | Robert Haschke | // converter from rsb utterance
|
36 | 0c286af0 | Simon Schulz | class UtteranceRSB : public Utterance { |
37 | f150aab5 | Robert Haschke | 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):
|
||
68 | audio_data->sample_signed = false; // and fall through: |
||
69 | case (rst::audition::SoundChunk::SAMPLE_S8):
|
||
70 | audio_data->sample_bit = 8;
|
||
71 | break;
|
||
72 | |||
73 | case (rst::audition::SoundChunk::SAMPLE_U16):
|
||
74 | audio_data->sample_signed = false; // and fall through: |
||
75 | case (rst::audition::SoundChunk::SAMPLE_S16):
|
||
76 | audio_data->sample_bit = 16;
|
||
77 | break;
|
||
78 | |||
79 | case (rst::audition::SoundChunk::SAMPLE_U24):
|
||
80 | audio_data->sample_signed = false; // and fall through: |
||
81 | case (rst::audition::SoundChunk::SAMPLE_S24):
|
||
82 | audio_data->sample_bit = 24;
|
||
83 | break;
|
||
84 | |||
85 | default:
|
||
86 | printf("> invalid sample type %d in RST SoundChunk! ignoring request!\n", sound_chunk.sample_type());
|
||
87 | throw runtime_error("UtteranceRSB::convert_audio_data() unsupported sample type in rst::audition::SoundChunk");
|
||
88 | } |
||
89 | |||
90 | // bitrate
|
||
91 | audio_data->sample_rate = sound_chunk.rate(); |
||
92 | |||
93 | // endianness
|
||
94 | if (sound_chunk.endianness() == rst::audition::SoundChunk::ENDIAN_LITTLE) {
|
||
95 | audio_data->sample_big_endian = false;
|
||
96 | } |
||
97 | else if (sound_chunk.endianness() == rst::audition::SoundChunk::ENDIAN_BIG) { |
||
98 | audio_data->sample_big_endian = true;
|
||
99 | } |
||
100 | else {
|
||
101 | printf("> invalid SoundChunk byte_format");
|
||
102 | throw runtime_error("UtteranceRSB::convert_audio_data() unsupported byte_format in rst::audition::SoundChunk");
|
||
103 | } |
||
104 | |||
105 | // number of channels
|
||
106 | audio_data->sample_channels = sound_chunk.channels(); |
||
107 | |||
108 | printf("> new AudioData: %s\n", audio_data->to_string().c_str());
|
||
109 | } |
||
110 | |||
111 | void extract_phonemes(rst::audition::Utterance rst_utterance) {
|
||
112 | // extract phoneme vector
|
||
113 | phonemes_vector.clear(); |
||
114 | for (int i = 0; i < rst_utterance.phonemes().element().size(); i++) { |
||
115 | rst::audition::Phoneme rst_phoneme = rst_utterance.phonemes().element().Get(i); |
||
116 | Utterance::symbol_duration_pair_t phoneme = make_pair(rst_phoneme.symbol(), rst_phoneme.duration()); |
||
117 | phonemes_vector.push_back(phoneme); |
||
118 | } |
||
119 | } |
||
120 | 0c286af0 | Simon Schulz | }; |