From b26c1efe0f3978fce7290bd53109dc7504bf0037 Mon Sep 17 00:00:00 2001 From: YangZhou <56786796+SmileGoat@users.noreply.github.com> Date: Mon, 24 Jan 2022 19:49:53 +0800 Subject: [PATCH] add glog gflags gtest openfst&base_types, test=doc (#1382) --- speechx/CMakeLists.txt | 46 +++++++++++++++++- speechx/speechx/base/basic_types.h | 60 ++++++++++++++++++++++++ speechx/speechx/base/macros.h | 23 +++++++++ speechx/speechx/kaldi/base/kaldi-types.h | 8 ++-- 4 files changed, 132 insertions(+), 5 deletions(-) create mode 100644 speechx/speechx/base/basic_types.h create mode 100644 speechx/speechx/base/macros.h diff --git a/speechx/CMakeLists.txt b/speechx/CMakeLists.txt index 12dc594f..e003136a 100644 --- a/speechx/CMakeLists.txt +++ b/speechx/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required(VERSION 3.14 FATAL_ERROR) -project(deepspeech VERSION 0.1) +project(paddlespeech VERSION 0.1) set(CMAKE_VERBOSE_MAKEFILE on) # set std-14 @@ -49,6 +49,50 @@ FetchContent_Declare( ) FetchContent_MakeAvailable(libsndfile) +# gflags +FetchContent_Declare( + gflags + URL https://github.com/gflags/gflags/archive/v2.2.1.zip + URL_HASH SHA256=4e44b69e709c826734dbbbd5208f61888a2faf63f239d73d8ba0011b2dccc97a +) +FetchContent_MakeAvailable(gflags) +include_directories(${gflags_BINARY_DIR}/include) + +# glog +FetchContent_Declare( + glog + URL https://github.com/google/glog/archive/v0.4.0.zip + URL_HASH SHA256=9e1b54eb2782f53cd8af107ecf08d2ab64b8d0dc2b7f5594472f3bd63ca85cdc +) +FetchContent_MakeAvailable(glog) +include_directories(${glog_BINARY_DIR}) + +# gtest +FetchContent_Declare(googletest + URL https://github.com/google/googletest/archive/release-1.10.0.zip + URL_HASH SHA256=94c634d499558a76fa649edb13721dce6e98fb1e7018dfaeba3cd7a083945e91 +) +FetchContent_MakeAvailable(googletest) + +# openfst +set(openfst_SOURCE_DIR ${fc_patch}/openfst-src) +set(openfst_BINARY_DIR ${fc_patch}/openfst-build) +set(openfst_PREFIX_DIR ${fc_patch}/openfst-subbuild/openfst-populate-prefix) +ExternalProject_Add(openfst + URL https://github.com/mjansche/openfst/archive/refs/tags/1.7.2.zip + URL_HASH SHA256=ffc56931025579a8af3515741c0f3b0fc3a854c023421472c07ca0c6389c75e6 + SOURCE_DIR ${openfst_SOURCE_DIR} + BINARY_DIR ${openfst_BINARY_DIR} + CONFIGURE_COMMAND ${openfst_SOURCE_DIR}/configure --prefix=${openfst_PREFIX_DIR} + "CPPFLAGS=-I${gflags_BINARY_DIR}/include -I${glog_SOURCE_DIR}/src -I${glog_BINARY_DIR}" + "LDFLAGS=-L${gflags_BINARY_DIR} -L${glog_BINARY_DIR}" + "LIBS=-lgflags_nothreads -lglog -lpthread" + BUILD_COMMAND make -j 4 +) +add_dependencies(openfst gflags glog) +link_directories(${openfst_PREFIX_DIR}/lib) +include_directories(${openfst_PREFIX_DIR}/include) + add_subdirectory(speechx) #openblas diff --git a/speechx/speechx/base/basic_types.h b/speechx/speechx/base/basic_types.h new file mode 100644 index 00000000..1966c021 --- /dev/null +++ b/speechx/speechx/base/basic_types.h @@ -0,0 +1,60 @@ +// Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#pragma once + +#include "kaldi/base/kaldi-types.h" + +#include + +typedef float BaseFloat; +typedef double double64; + +typedef signed char int8; +typedef short int16; +typedef int int32; + +#if defined(__LP64__) && !defined(OS_MACOSX) && !defined(OS_OPENBSD) +typedef long int64; +#else +typedef long long int64; +#endif + +typedef unsigned char uint8; +typedef unsigned short uint16; +typedef unsigned int uint32; + +if defined(__LP64__) && !defined(OS_MACOSX) && !defined(OS_OPENBSD) +typedef unsigned long uint64; +#else +typedef unsigned long long uint64; +#endif + +typedef signed int char32; + +const uint8 kuint8max = (( uint8) 0xFF); +const uint16 kuint16max = ((uint16) 0xFFFF); +const uint32 kuint32max = ((uint32) 0xFFFFFFFF); +const uint64 kuint64max = ((uint64) (0xFFFFFFFFFFFFFFFFLL)); +const int8 kint8min = (( int8) 0x80); +const int8 kint8max = (( int8) 0x7F); +const int16 kint16min = (( int16) 0x8000); +const int16 kint16max = (( int16) 0x7FFF); +const int32 kint32min = (( int32) 0x80000000); +const int32 kint32max = (( int32) 0x7FFFFFFF); +const int64 kint64min = (( int64) (0x8000000000000000LL)); +const int64 kint64max = (( int64) (0x7FFFFFFFFFFFFFFFLL)); + +const BaseFloat kBaseFloatMax = std::numeric_limits::max(); +const BaseFloat kBaseFloatMin = std::numeric_limits::min(); diff --git a/speechx/speechx/base/macros.h b/speechx/speechx/base/macros.h new file mode 100644 index 00000000..c8d254d6 --- /dev/null +++ b/speechx/speechx/base/macros.h @@ -0,0 +1,23 @@ +// Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#pragma once + +namespace ppspeech { + +#define DISALLOW_COPY_AND_ASSIGN(TypeName) \ + TypeName(const TypeName&) = delete; \ + void operator=(const TypeName&) = delete + +} // namespace pp_speech \ No newline at end of file diff --git a/speechx/speechx/kaldi/base/kaldi-types.h b/speechx/speechx/kaldi/base/kaldi-types.h index 16a1a5b9..4fa8f224 100644 --- a/speechx/speechx/kaldi/base/kaldi-types.h +++ b/speechx/speechx/kaldi/base/kaldi-types.h @@ -41,7 +41,7 @@ typedef float BaseFloat; // for discussion on what to do if you need compile kaldi // without OpenFST, see the bottom of this this file -/* + #include namespace kaldi { @@ -54,10 +54,10 @@ namespace kaldi { typedef float float32; typedef double double64; } // end namespace kaldi -*/ + // In a theoretical case you decide compile Kaldi without the OpenFST // comment the previous namespace statement and uncomment the following - +/* namespace kaldi { typedef int8_t int8; typedef int16_t int16; @@ -71,6 +71,6 @@ namespace kaldi { typedef float float32; typedef double double64; } // end namespace kaldi - +*/ #endif // KALDI_BASE_KALDI_TYPES_H_