Skip to content

Commit

Permalink
Fix warnings in preparation for openfst 1.8.0
Browse files Browse the repository at this point in the history
  • Loading branch information
nshmyrev committed Dec 22, 2020
1 parent dc3d03d commit 8997a58
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 38 deletions.
4 changes: 2 additions & 2 deletions c/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ libvosk.a: $(VOSK_SOURCES:.cc=.o)
g++ $(CFLAGS) -c -o $@ $<

%.o: %.cc
g++ -std=c++11 $(CFLAGS) -c -o $@ $<
g++ -std=c++17 $(CFLAGS) -c -o $@ $<

clean:
rm -f *.o *.a test_vosk
rm -f *.o *.a test_vosk test_vosk_speaker
1 change: 1 addition & 0 deletions c/test_vosk.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,6 @@ int main() {

vosk_recognizer_free(recognizer);
vosk_model_free(model);
fclose(wavin);
return 0;
}
2 changes: 1 addition & 1 deletion csharp/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
KALDI_ROOT ?= $(HOME)/kaldi
CFLAGS := -std=c++11 -g -O2 -DPIC -fPIC -Wno-unused-function
CFLAGS := -std=c++17 -g -O2 -DPIC -fPIC -Wno-unused-function
CPPFLAGS := -I$(KALDI_ROOT)/src -I$(KALDI_ROOT)/tools/openfst/include -I../src -DFST_NO_DYNAMIC_LINKING

KALDI_LIBS = \
Expand Down
2 changes: 1 addition & 1 deletion java/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
KALDI_ROOT ?= $(HOME)/kaldi
CFLAGS := -g -O2 -DPIC -fPIC -Wno-unused-function
CFLAGS := -g -O2 -DPIC -fPIC -Wno-unused-function -std=c++17
CPPFLAGS := -I$(JAVA_HOME)/include -I$(JAVA_HOME)/include/linux -I$(KALDI_ROOT)/src -I$(KALDI_ROOT)/tools/openfst/include -I../src

KALDI_LIBS = \
Expand Down
5 changes: 3 additions & 2 deletions nodejs/binding.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
'vosk_wrap.cc',
],
'cflags': [
'-std=c++11',
'-std=c++17',
'-DFST_NO_DYNAMIC_LINKING',
'-Wno-deprecated-declarations',
'-Wno-sign-compare',
Expand All @@ -22,13 +22,14 @@
'cflags_cc!' : [
'-fno-rtti',
'-fno-exceptions',
'-std=gnu++1y',
],
'conditions': [
['OS == "mac"', {
'xcode_settings': {
'GCC_ENABLE_CPP_EXCEPTIONS': 'YES',
'GCC_ENABLE_CPP_RTTI': 'YES',
'CLANG_CXX_LANGUAGE_STANDARD': 'c++11'
'CLANG_CXX_LANGUAGE_STANDARD': 'c++17'
}
}]
],
Expand Down
2 changes: 1 addition & 1 deletion python/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def run(self):
extra_objects = [kaldi_root + '/' + x for x in kaldi_static_libs],
sources = ['vosk/' + x for x in sources],
extra_link_args = kaldi_link_args,
extra_compile_args = ['-std=c++11', '-Wno-sign-compare', '-Wno-unused-variable', '-Wno-unused-local-typedefs'])
extra_compile_args = ['-std=c++17', '-Wno-sign-compare', '-Wno-unused-variable', '-Wno-unused-local-typedefs'])

setuptools.setup(
name="vosk",
Expand Down
54 changes: 27 additions & 27 deletions src/json.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ namespace {
case '\t': output += "\\t"; break;
default : output += str[i]; break;
}
return std::move( output );
return output;
}
}

Expand Down Expand Up @@ -291,10 +291,10 @@ class JSON
/// Functions for getting primitives from the JSON object.
bool IsNull() const { return Type == Class::Null; }

string ToString() const { bool b; return std::move( ToString( b ) ); }
string ToString() const { bool b; return ToString(b); }
string ToString( bool &ok ) const {
ok = (Type == Class::String);
return ok ? std::move( json_escape( *Internal.String ) ): string("");
return ok ? json_escape( *Internal.String ) : string("");
}

double ToFloat() const { bool b; return ToFloat( b ); }
Expand Down Expand Up @@ -425,18 +425,18 @@ class JSON
};

JSON Array() {
return std::move( JSON::Make( JSON::Class::Array ) );
return JSON::Make( JSON::Class::Array );
}

template <typename... T>
JSON Array( T... args ) {
JSON arr = JSON::Make( JSON::Class::Array );
arr.append( args... );
return std::move( arr );
return arr;
}

JSON Object() {
return std::move( JSON::Make( JSON::Class::Object ) );
return JSON::Make( JSON::Class::Object );
}

std::ostream& operator<<( std::ostream &os, const JSON &json ) {
Expand All @@ -457,7 +457,7 @@ namespace {
++offset;
consume_ws( str, offset );
if( str[offset] == '}' ) {
++offset; return std::move( Object );
++offset; return Object;
}

while( true ) {
Expand All @@ -484,7 +484,7 @@ namespace {
}
}

return std::move( Object );
return Object;
}

JSON parse_array( const string &str, size_t &offset ) {
Expand All @@ -494,7 +494,7 @@ namespace {
++offset;
consume_ws( str, offset );
if( str[offset] == ']' ) {
++offset; return std::move( Array );
++offset; return Array;
}

while( true ) {
Expand All @@ -509,11 +509,11 @@ namespace {
}
else {
std::cerr << "ERROR: Array: Expected ',' or ']', found '" << str[offset] << "'\n";
return std::move( JSON::Make( JSON::Class::Array ) );
return JSON::Make( JSON::Class::Array );
}
}

return std::move( Array );
return Array;
}

JSON parse_string( const string &str, size_t &offset ) {
Expand All @@ -538,7 +538,7 @@ namespace {
val += c;
else {
std::cerr << "ERROR: String: Expected hex character in unicode escape, found '" << c << "'\n";
return std::move( JSON::Make( JSON::Class::String ) );
return JSON::Make( JSON::Class::String );
}
}
offset += 4;
Expand All @@ -551,7 +551,7 @@ namespace {
}
++offset;
String = val;
return std::move( String );
return String;
}

JSON parse_number( const string &str, size_t &offset ) {
Expand Down Expand Up @@ -580,7 +580,7 @@ namespace {
exp_str += c;
else if( !isspace( c ) && c != ',' && c != ']' && c != '}' ) {
std::cerr << "ERROR: Number: Expected a number for exponent, found '" << c << "'\n";
return std::move( JSON::Make( JSON::Class::Null ) );
return JSON::Make( JSON::Class::Null );
}
else
break;
Expand All @@ -589,7 +589,7 @@ namespace {
}
else if( !isspace( c ) && c != ',' && c != ']' && c != '}' ) {
std::cerr << "ERROR: Number: unexpected character '" << c << "'\n";
return std::move( JSON::Make( JSON::Class::Null ) );
return JSON::Make( JSON::Class::Null );
}
--offset;

Expand All @@ -601,7 +601,7 @@ namespace {
else
Number = std::stol( val );
}
return std::move( Number );
return Number;
}

JSON parse_bool( const string &str, size_t &offset ) {
Expand All @@ -612,35 +612,35 @@ namespace {
Bool = false;
else {
std::cerr << "ERROR: Bool: Expected 'true' or 'false', found '" << str.substr( offset, 5 ) << "'\n";
return std::move( JSON::Make( JSON::Class::Null ) );
return JSON::Make( JSON::Class::Null );
}
offset += (Bool.ToBool() ? 4 : 5);
return std::move( Bool );
return Bool;
}

JSON parse_null( const string &str, size_t &offset ) {
JSON Null;
if( str.substr( offset, 4 ) != "null" ) {
std::cerr << "ERROR: Null: Expected 'null', found '" << str.substr( offset, 4 ) << "'\n";
return std::move( JSON::Make( JSON::Class::Null ) );
return JSON::Make( JSON::Class::Null );
}
offset += 4;
return std::move( Null );
return Null;
}

JSON parse_next( const string &str, size_t &offset ) {
char value;
consume_ws( str, offset );
value = str[offset];
switch( value ) {
case '[' : return std::move( parse_array( str, offset ) );
case '{' : return std::move( parse_object( str, offset ) );
case '\"': return std::move( parse_string( str, offset ) );
case '[' : return parse_array( str, offset );
case '{' : return parse_object( str, offset );
case '\"': return parse_string( str, offset );
case 't' :
case 'f' : return std::move( parse_bool( str, offset ) );
case 'n' : return std::move( parse_null( str, offset ) );
case 'f' : return parse_bool( str, offset );
case 'n' : return parse_null( str, offset );
default : if( ( value <= '9' && value >= '0' ) || value == '-' )
return std::move( parse_number( str, offset ) );
return parse_number( str, offset );
}
std::cerr << "ERROR: Parse: Unknown starting character '" << value << "'\n";
return JSON();
Expand All @@ -649,7 +649,7 @@ namespace {

JSON JSON::Load( const string &str ) {
size_t offset = 0;
return std::move( parse_next( str, offset ) );
return parse_next( str, offset );
}

} // End Namespace json
4 changes: 2 additions & 2 deletions src/kaldi_recognizer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,9 @@ void KaldiRecognizer::InitRescoring()
{
if (model_->std_lm_fst_) {
fst::CacheOptions cache_opts(true, 50000);
fst::MapFstOptions mapfst_opts(cache_opts);
fst::ArcMapFstOptions mapfst_opts(cache_opts);
fst::StdToLatticeMapper<kaldi::BaseFloat> mapper;
lm_fst_ = new fst::MapFst<fst::StdArc, kaldi::LatticeArc, fst::StdToLatticeMapper<kaldi::BaseFloat> >(*model_->std_lm_fst_, mapper, mapfst_opts);
lm_fst_ = new fst::ArcMapFst<fst::StdArc, kaldi::LatticeArc, fst::StdToLatticeMapper<kaldi::BaseFloat> >(*model_->std_lm_fst_, mapper, mapfst_opts);
} else {
lm_fst_ = NULL;
}
Expand Down
2 changes: 1 addition & 1 deletion src/kaldi_recognizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class KaldiRecognizer {
SpkModel *spk_model_;
OnlineBaseFeature *spk_feature_;

fst::MapFst<fst::StdArc, kaldi::LatticeArc, fst::StdToLatticeMapper<kaldi::BaseFloat> > *lm_fst_;
fst::ArcMapFst<fst::StdArc, kaldi::LatticeArc, fst::StdToLatticeMapper<kaldi::BaseFloat> > *lm_fst_;

float sample_frequency_;
int32 frame_offset_;
Expand Down
2 changes: 1 addition & 1 deletion src/model.cc
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ void Model::ReadDataFiles()
if (stat(carpa_rxfilename_.c_str(), &buffer) == 0) {
KALDI_LOG << "Loading CARPA model from " << carpa_rxfilename_;
std_lm_fst_ = fst::ReadFstKaldi(std_fst_rxfilename_);
fst::Project(std_lm_fst_, fst::PROJECT_OUTPUT);
fst::Project(std_lm_fst_, fst::ProjectType::OUTPUT);
if (std_lm_fst_->Properties(fst::kILabelSorted, true) == 0) {
fst::ILabelCompare<fst::StdArc> ilabel_comp;
fst::ArcSort(std_lm_fst_, ilabel_comp);
Expand Down

0 comments on commit 8997a58

Please sign in to comment.