From ffaf9845cb1c5834ab576d2d8466c8582b2e22c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=A9=AC=E4=B8=B9?= Date: Fri, 4 Nov 2022 21:56:16 +0800 Subject: [PATCH 01/13] Add iOS build files and test application. --- runtime/core/decoder/CMakeLists.txt | 7 +- runtime/core/decoder/ios_asr_model.cc | 280 +++++ runtime/core/decoder/ios_asr_model.h | 67 ++ .../core/patch/openfst/src/bin/CMakeLists.txt | 86 ++ runtime/core/toolchains/ios.toolchain.cmake | 1014 +++++++++++++++++ runtime/ios/CMakeLists.txt | 75 ++ runtime/ios/README.md | 42 + .../WenetDemo.xcodeproj/project.pbxproj | 563 +++++++++ .../contents.xcworkspacedata | 7 + .../xcshareddata/IDEWorkspaceChecks.plist | 8 + .../ios/WenetDemo/WenetDemo/AppDelegate.swift | 34 + .../AccentColor.colorset/Contents.json | 11 + .../AppIcon.appiconset/Contents.json | 13 + .../WenetDemo/Assets.xcassets/Contents.json | 6 + .../Base.lproj/LaunchScreen.storyboard | 25 + .../WenetDemo/Base.lproj/Main.storyboard | 55 + runtime/ios/WenetDemo/WenetDemo/Info.plist | 27 + .../WenetDemo/WenetDemo/SceneDelegate.swift | 50 + .../WenetDemo/WenetDemo/ViewController.swift | 116 ++ .../ios/WenetDemo/WenetDemo/model/.gitkeep | 0 .../wenet/WenetDemo-Bridging-Header.h | 5 + runtime/ios/WenetDemo/WenetDemo/wenet/wenet.h | 26 + .../ios/WenetDemo/WenetDemo/wenet/wenet.mm | 114 ++ runtime/ios/api | 1 + runtime/ios/bin | 1 + runtime/ios/build/Podfile | 4 + runtime/ios/cmake | 1 + runtime/ios/decoder | 1 + runtime/ios/frontend | 1 + runtime/ios/kaldi | 1 + runtime/ios/patch | 1 + runtime/ios/post_processor | 1 + runtime/ios/test | 1 + runtime/ios/toolchains | 1 + runtime/ios/utils | 1 + runtime/ios/websocket | 1 + 36 files changed, 2645 insertions(+), 2 deletions(-) create mode 100644 runtime/core/decoder/ios_asr_model.cc create mode 100644 runtime/core/decoder/ios_asr_model.h create mode 100644 runtime/core/patch/openfst/src/bin/CMakeLists.txt create mode 100644 runtime/core/toolchains/ios.toolchain.cmake create mode 100644 runtime/ios/CMakeLists.txt create mode 100644 runtime/ios/README.md create mode 100644 runtime/ios/WenetDemo/WenetDemo.xcodeproj/project.pbxproj create mode 100644 runtime/ios/WenetDemo/WenetDemo.xcodeproj/project.xcworkspace/contents.xcworkspacedata create mode 100644 runtime/ios/WenetDemo/WenetDemo.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist create mode 100644 runtime/ios/WenetDemo/WenetDemo/AppDelegate.swift create mode 100644 runtime/ios/WenetDemo/WenetDemo/Assets.xcassets/AccentColor.colorset/Contents.json create mode 100644 runtime/ios/WenetDemo/WenetDemo/Assets.xcassets/AppIcon.appiconset/Contents.json create mode 100644 runtime/ios/WenetDemo/WenetDemo/Assets.xcassets/Contents.json create mode 100644 runtime/ios/WenetDemo/WenetDemo/Base.lproj/LaunchScreen.storyboard create mode 100644 runtime/ios/WenetDemo/WenetDemo/Base.lproj/Main.storyboard create mode 100644 runtime/ios/WenetDemo/WenetDemo/Info.plist create mode 100644 runtime/ios/WenetDemo/WenetDemo/SceneDelegate.swift create mode 100644 runtime/ios/WenetDemo/WenetDemo/ViewController.swift create mode 100644 runtime/ios/WenetDemo/WenetDemo/model/.gitkeep create mode 100644 runtime/ios/WenetDemo/WenetDemo/wenet/WenetDemo-Bridging-Header.h create mode 100644 runtime/ios/WenetDemo/WenetDemo/wenet/wenet.h create mode 100644 runtime/ios/WenetDemo/WenetDemo/wenet/wenet.mm create mode 120000 runtime/ios/api create mode 120000 runtime/ios/bin create mode 100644 runtime/ios/build/Podfile create mode 120000 runtime/ios/cmake create mode 120000 runtime/ios/decoder create mode 120000 runtime/ios/frontend create mode 120000 runtime/ios/kaldi create mode 120000 runtime/ios/patch create mode 120000 runtime/ios/post_processor create mode 120000 runtime/ios/test create mode 120000 runtime/ios/toolchains create mode 120000 runtime/ios/utils create mode 120000 runtime/ios/websocket diff --git a/runtime/core/decoder/CMakeLists.txt b/runtime/core/decoder/CMakeLists.txt index 098fdcdb5e..d6924b81c8 100644 --- a/runtime/core/decoder/CMakeLists.txt +++ b/runtime/core/decoder/CMakeLists.txt @@ -7,8 +7,8 @@ set(decoder_srcs ctc_endpoint.cc ) -if(NOT TORCH AND NOT ONNX AND NOT XPU) - message(FATAL_ERROR "Please build with TORCH or ONNX or XPU!!!") +if(NOT TORCH AND NOT ONNX AND NOT XPU AND NOT IOS) + message(FATAL_ERROR "Please build with TORCH or ONNX or XPU or IOS!!!") endif() if(TORCH) list(APPEND decoder_srcs torch_asr_model.cc) @@ -16,6 +16,9 @@ endif() if(ONNX) list(APPEND decoder_srcs onnx_asr_model.cc) endif() +if(IOS) + list(APPEND decoder_srcs ios_asr_model.cc) +endif() add_library(decoder STATIC ${decoder_srcs}) target_link_libraries(decoder PUBLIC kaldi-decoder frontend diff --git a/runtime/core/decoder/ios_asr_model.cc b/runtime/core/decoder/ios_asr_model.cc new file mode 100644 index 0000000000..259b8f4c64 --- /dev/null +++ b/runtime/core/decoder/ios_asr_model.cc @@ -0,0 +1,280 @@ +// Copyright (c) 2020 Mobvoi Inc (Binbin Zhang, Di Wu) +// 2022 Binbin Zhang (binbzha@qq.com) +// +// 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. + + +#include "decoder/ios_asr_model.h" + +#include +#include +#include +#include + +#include "torch/script.h" +//#include "torch/torch.h" + +namespace wenet { + +void IosAsrModel::InitEngineThreads(int num_threads) { + // For multi-thread performance + //at::set_num_threads(num_threads); + // Note: Do not call the set_num_interop_threads function more than once. + // Please see https://github.com/pytorch/pytorch/blob/master/aten/src/ATen/ + // ParallelThreadPoolNative.cpp#L54-L56 + //at::set_num_interop_threads(1); + //VLOG(1) << "Num intra-op threads: " << at::get_num_threads(); + //VLOG(1) << "Num inter-op threads: " << at::get_num_interop_threads(); +} + +void IosAsrModel::Read(const std::string& model_path) { + torch::DeviceType device = at::kCPU; +#ifdef USE_GPU + if (!torch::cuda::is_available()) { + VLOG(1) << "CUDA is not available! Please check your GPU settings"; + throw std::runtime_error("CUDA is not available!"); + } else { + VLOG(1) << "CUDA available! Running on GPU"; + device = at::kCUDA; + } +#endif + torch::jit::script::Module model = torch::jit::load(model_path, device); + model_ = std::make_shared(std::move(model)); + torch::NoGradGuard no_grad; + model_->eval(); + torch::jit::IValue o1 = model_->run_method("subsampling_rate"); + CHECK_EQ(o1.isInt(), true); + subsampling_rate_ = o1.toInt(); + torch::jit::IValue o2 = model_->run_method("right_context"); + CHECK_EQ(o2.isInt(), true); + right_context_ = o2.toInt(); + torch::jit::IValue o3 = model_->run_method("sos_symbol"); + CHECK_EQ(o3.isInt(), true); + sos_ = o3.toInt(); + torch::jit::IValue o4 = model_->run_method("eos_symbol"); + CHECK_EQ(o4.isInt(), true); + eos_ = o4.toInt(); + torch::jit::IValue o5 = model_->run_method("is_bidirectional_decoder"); + CHECK_EQ(o5.isBool(), true); + is_bidirectional_decoder_ = o5.toBool(); + + VLOG(1) << "Torch Model Info:"; + VLOG(1) << "\tsubsampling_rate " << subsampling_rate_; + VLOG(1) << "\tright context " << right_context_; + VLOG(1) << "\tsos " << sos_; + VLOG(1) << "\teos " << eos_; + VLOG(1) << "\tis bidirectional decoder " << is_bidirectional_decoder_; +} + +IosAsrModel::IosAsrModel(const IosAsrModel& other) { + // 1. Init the model info + right_context_ = other.right_context_; + subsampling_rate_ = other.subsampling_rate_; + sos_ = other.sos_; + eos_ = other.eos_; + is_bidirectional_decoder_ = other.is_bidirectional_decoder_; + chunk_size_ = other.chunk_size_; + num_left_chunks_ = other.num_left_chunks_; + offset_ = other.offset_; + // 2. Model copy, just copy the model ptr since: + // PyTorch allows using multiple CPU threads during TorchScript model + // inference, please see https://pytorch.org/docs/stable/notes/cpu_ + // threading_torchscript_inference.html + model_ = other.model_; + + // NOTE(Binbin Zhang): + // inner states for forward are not copied here. +} + +std::shared_ptr IosAsrModel::Copy() const { + auto asr_model = std::make_shared(*this); + // Reset the inner states for new decoding + asr_model->Reset(); + return asr_model; +} + +void IosAsrModel::Reset() { + offset_ = 0; + att_cache_ = std::move(torch::zeros({0, 0, 0, 0})); + cnn_cache_ = std::move(torch::zeros({0, 0, 0, 0})); + encoder_outs_.clear(); + cached_feature_.clear(); +} + +void IosAsrModel::ForwardEncoderFunc( + const std::vector>& chunk_feats, + std::vector>* out_prob) { + // 1. Prepare libtorch required data, splice cached_feature_ and chunk_feats + // The first dimension is for batchsize, which is 1. + int num_frames = cached_feature_.size() + chunk_feats.size(); + const int feature_dim = chunk_feats[0].size(); + torch::Tensor feats = + torch::zeros({1, num_frames, feature_dim}, torch::kFloat); + for (size_t i = 0; i < cached_feature_.size(); ++i) { + torch::Tensor row = + torch::from_blob(const_cast(cached_feature_[i].data()), + {feature_dim}, torch::kFloat) + .clone(); + feats[0][i] = std::move(row); + } + for (size_t i = 0; i < chunk_feats.size(); ++i) { + torch::Tensor row = + torch::from_blob(const_cast(chunk_feats[i].data()), + {feature_dim}, torch::kFloat) + .clone(); + feats[0][cached_feature_.size() + i] = std::move(row); + } + + // 2. Encoder chunk forward +#ifdef USE_GPU + feats = feats.to(at::kCUDA); + att_cache_ = att_cache_.to(at::kCUDA); + cnn_cache_ = cnn_cache_.to(at::kCUDA); +#endif + int required_cache_size = chunk_size_ * num_left_chunks_; + torch::NoGradGuard no_grad; + std::vector inputs = {feats, offset_, required_cache_size, + att_cache_, cnn_cache_}; + + // Refer interfaces in wenet/transformer/asr_model.py + auto outputs = + model_->get_method("forward_encoder_chunk")(inputs).toTuple()->elements(); + CHECK_EQ(outputs.size(), 3); +#ifdef USE_GPU + torch::Tensor chunk_out = outputs[0].toTensor().to(at::kCPU); + att_cache_ = outputs[1].toTensor().to(at::kCPU); + cnn_cache_ = outputs[2].toTensor().to(at::kCPU); +#else + torch::Tensor chunk_out = outputs[0].toTensor(); + att_cache_ = outputs[1].toTensor(); + cnn_cache_ = outputs[2].toTensor(); +#endif + offset_ += chunk_out.size(1); + + // The first dimension of returned value is for batchsize, which is 1 +#ifdef USE_GPU + chunk_out = chunk_out.to(at::kCUDA); + torch::Tensor ctc_log_probs = + model_->run_method("ctc_activation", chunk_out).toTensor(); + ctc_log_probs = ctc_log_probs.to(at::kCPU)[0]; + encoder_outs_.push_back(std::move(chunk_out.to(at::kCPU))); +#else + torch::Tensor ctc_log_probs = + model_->run_method("ctc_activation", chunk_out).toTensor()[0]; + encoder_outs_.push_back(std::move(chunk_out)); +#endif + + // Copy to output + int num_outputs = ctc_log_probs.size(0); + int output_dim = ctc_log_probs.size(1); + out_prob->resize(num_outputs); + for (int i = 0; i < num_outputs; i++) { + (*out_prob)[i].resize(output_dim); + memcpy((*out_prob)[i].data(), ctc_log_probs[i].data_ptr(), + sizeof(float) * output_dim); + } +} + +float IosAsrModel::ComputeAttentionScore(const torch::Tensor& prob, + const std::vector& hyp, + int eos) { + float score = 0.0f; + auto accessor = prob.accessor(); + for (size_t j = 0; j < hyp.size(); ++j) { + score += accessor[j][hyp[j]]; + } + score += accessor[hyp.size()][eos]; + return score; +} + +void IosAsrModel::AttentionRescoring( + const std::vector>& hyps, float reverse_weight, + std::vector* rescoring_score) { + CHECK(rescoring_score != nullptr); + int num_hyps = hyps.size(); + rescoring_score->resize(num_hyps, 0.0f); + + if (num_hyps == 0) { + return; + } + // No encoder output + if (encoder_outs_.size() == 0) { + return; + } + + torch::NoGradGuard no_grad; + // Step 1: Prepare input for libtorch + torch::Tensor hyps_length = torch::zeros({num_hyps}, torch::kLong); + int max_hyps_len = 0; + for (size_t i = 0; i < num_hyps; ++i) { + int length = hyps[i].size() + 1; + max_hyps_len = std::max(length, max_hyps_len); + hyps_length[i] = static_cast(length); + } + torch::Tensor hyps_tensor = + torch::zeros({num_hyps, max_hyps_len}, torch::kLong); + for (size_t i = 0; i < num_hyps; ++i) { + const std::vector& hyp = hyps[i]; + hyps_tensor[i][0] = sos_; + for (size_t j = 0; j < hyp.size(); ++j) { + hyps_tensor[i][j + 1] = hyp[j]; + } + } + + // Step 2: Forward attention decoder by hyps and corresponding encoder_outs_ + torch::Tensor encoder_out = torch::cat(encoder_outs_, 1); +#ifdef USE_GPU + hyps_tensor = hyps_tensor.to(at::kCUDA); + hyps_length = hyps_length.to(at::kCUDA); + encoder_out = encoder_out.to(at::kCUDA); +#endif + auto outputs = model_ + ->run_method("forward_attention_decoder", hyps_tensor, + hyps_length, encoder_out, reverse_weight) + .toTuple() + ->elements(); +#ifdef USE_GPU + auto probs = outputs[0].toTensor().to(at::kCPU); + auto r_probs = outputs[1].toTensor().to(at::kCPU); +#else + auto probs = outputs[0].toTensor(); + auto r_probs = outputs[1].toTensor(); +#endif + CHECK_EQ(probs.size(0), num_hyps); + CHECK_EQ(probs.size(1), max_hyps_len); + + // Step 3: Compute rescoring score + for (size_t i = 0; i < num_hyps; ++i) { + const std::vector& hyp = hyps[i]; + float score = 0.0f; + // left-to-right decoder score + score = ComputeAttentionScore(probs[i], hyp, eos_); + // Optional: Used for right to left score + float r_score = 0.0f; + if (is_bidirectional_decoder_ && reverse_weight > 0) { + // right-to-left score + CHECK_EQ(r_probs.size(0), num_hyps); + CHECK_EQ(r_probs.size(1), max_hyps_len); + std::vector r_hyp(hyp.size()); + std::reverse_copy(hyp.begin(), hyp.end(), r_hyp.begin()); + // right to left decoder score + r_score = ComputeAttentionScore(r_probs[i], r_hyp, eos_); + } + + // combined left-to-right and right-to-left score + (*rescoring_score)[i] = + score * (1 - reverse_weight) + r_score * reverse_weight; + } +} + +} // namespace wenet diff --git a/runtime/core/decoder/ios_asr_model.h b/runtime/core/decoder/ios_asr_model.h new file mode 100644 index 0000000000..0b9f504063 --- /dev/null +++ b/runtime/core/decoder/ios_asr_model.h @@ -0,0 +1,67 @@ +// Copyright (c) 2020 Mobvoi Inc (Binbin Zhang, Di Wu) +// 2022 Binbin Zhang (binbzha@qq.com) +// +// 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. + + +#ifndef DECODER_IOS_ASR_MODEL_H_ +#define DECODER_IOS_ASR_MODEL_H_ + +#include +#include +#include + +#include "torch/script.h" +//#include "torch/torch.h" + +#include "decoder/asr_model.h" +#include "utils/utils.h" + +namespace wenet { + +class IosAsrModel : public AsrModel { + public: + // Note: Do not call the InitEngineThreads function more than once. + static void InitEngineThreads(int num_threads = 1); + + public: + using TorchModule = torch::jit::script::Module; + IosAsrModel() = default; + IosAsrModel(const IosAsrModel& other); + void Read(const std::string& model_path); + std::shared_ptr torch_model() const { return model_; } + void Reset() override; + void AttentionRescoring(const std::vector>& hyps, + float reverse_weight, + std::vector* rescoring_score) override; + std::shared_ptr Copy() const override; + + protected: + void ForwardEncoderFunc(const std::vector>& chunk_feats, + std::vector>* ctc_prob) override; + + float ComputeAttentionScore(const torch::Tensor& prob, + const std::vector& hyp, int eos); + + private: + std::shared_ptr model_ = nullptr; + std::vector encoder_outs_; + // transformer/conformer attention cache + torch::Tensor att_cache_ = torch::zeros({0, 0, 0, 0}); + // conformer-only conv_module cache + torch::Tensor cnn_cache_ = torch::zeros({0, 0, 0, 0}); +}; + +} // namespace wenet + +#endif // DECODER_IOS_ASR_MODEL_H_ diff --git a/runtime/core/patch/openfst/src/bin/CMakeLists.txt b/runtime/core/patch/openfst/src/bin/CMakeLists.txt new file mode 100644 index 0000000000..92ff3824db --- /dev/null +++ b/runtime/core/patch/openfst/src/bin/CMakeLists.txt @@ -0,0 +1,86 @@ +function (add_executable2 _name) + add_executable(${ARGV}) + if (TARGET ${_name}) + target_link_libraries(${_name} fstscript fst ${CMAKE_DL_LIBS}) + set_target_properties(${_name} PROPERTIES FOLDER bin) + endif() + + install(TARGETS ${_name} RUNTIME DESTINATION . BUNDLE DESTINATION bin) +endfunction() + +include_directories(../include ../script/) + +add_executable2(fstarcsort fstarcsort-main.cc fstarcsort.cc) + +add_executable2(fstclosure fstclosure-main.cc fstclosure.cc) + +add_executable2(fstcompile fstcompile-main.cc fstcompile.cc) + +add_executable2(fstcompose fstcompose-main.cc fstcompose.cc) + +add_executable2(fstconcat fstconcat-main.cc fstconcat.cc) + +add_executable2(fstconnect fstconnect-main.cc fstconnect.cc) + +add_executable2(fstconvert fstconvert-main.cc fstconvert.cc) + +add_executable2(fstdeterminize fstdeterminize-main.cc fstdeterminize.cc) + +add_executable2(fstdifference fstdifference-main.cc fstdifference.cc) + +add_executable2(fstdisambiguate fstdisambiguate-main.cc fstdisambiguate.cc) + +add_executable2(fstdraw fstdraw-main.cc fstdraw.cc) + +add_executable2(fstencode fstencode-main.cc fstencode.cc) + +add_executable2(fstepsnormalize fstepsnormalize-main.cc fstepsnormalize.cc) + +add_executable2(fstequal fstequal-main.cc fstequal.cc) + +add_executable2(fstequivalent fstequivalent-main.cc fstequivalent.cc) + +add_executable2(fstinfo fstinfo-main.cc fstinfo.cc) + +add_executable2(fstintersect fstintersect-main.cc fstintersect.cc) + +add_executable2(fstinvert fstinvert-main.cc fstinvert.cc) + +add_executable2(fstisomorphic fstisomorphic-main.cc fstisomorphic.cc) + +add_executable2(fstmap fstmap-main.cc fstmap.cc) + +add_executable2(fstminimize fstminimize-main.cc fstminimize.cc) + +add_executable2(fstprint fstprint-main.cc fstprint.cc) + +add_executable2(fstproject fstproject-main.cc fstproject.cc) + +add_executable2(fstprune fstprune-main.cc fstprune.cc) + +add_executable2(fstpush fstpush-main.cc fstpush.cc) + +add_executable2(fstrandgen fstrandgen-main.cc fstrandgen.cc) + +add_executable2(fstrelabel fstrelabel-main.cc fstrelabel.cc) + +add_executable2(fstreplace fstreplace-main.cc fstreplace.cc) + +add_executable2(fstreverse fstreverse-main.cc fstreverse.cc) + +add_executable2(fstreweight fstreweight-main.cc fstreweight.cc) + +add_executable2(fstrmepsilon fstrmepsilon-main.cc fstrmepsilon.cc) + +add_executable2(fstshortestdistance fstshortestdistance-main.cc fstshortestdistance.cc) + +add_executable2(fstshortestpath fstshortestpath-main.cc fstshortestpath.cc) + +add_executable2(fstsymbols fstsymbols-main.cc fstsymbols.cc) + +add_executable2(fstsynchronize fstsynchronize-main.cc fstsynchronize.cc) + +add_executable2(fsttopsort fsttopsort-main.cc fsttopsort.cc) + +add_executable2(fstunion fstunion-main.cc fstunion.cc) + diff --git a/runtime/core/toolchains/ios.toolchain.cmake b/runtime/core/toolchains/ios.toolchain.cmake new file mode 100644 index 0000000000..5c8add8c59 --- /dev/null +++ b/runtime/core/toolchains/ios.toolchain.cmake @@ -0,0 +1,1014 @@ +# This file is part of the ios-cmake project. It was retrieved from +# https://github.com/leetal/ios-cmake.git, which is a fork of +# https://github.com/gerstrong/ios-cmake.git, which is a fork of +# https://github.com/cristeab/ios-cmake.git, which is a fork of +# https://code.google.com/p/ios-cmake/. Which in turn is based off of +# the Platform/Darwin.cmake and Platform/UnixPaths.cmake files which +# are included with CMake 2.8.4 +# +# The ios-cmake project is licensed under the new BSD license. +# +# Copyright (c) 2014, Bogdan Cristea and LTE Engineering Software, +# Kitware, Inc., Insight Software Consortium. All rights reserved. +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# 3. Neither the name of the copyright holder nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +# COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# +# This file is based off of the Platform/Darwin.cmake and +# Platform/UnixPaths.cmake files which are included with CMake 2.8.4 +# It has been altered for iOS development. +# +# Updated by Alex Stewart (alexs.mac@gmail.com) +# +# ***************************************************************************** +# Now maintained by Alexander Widerberg (widerbergaren [at] gmail.com) +# under the BSD-3-Clause license +# https://github.com/leetal/ios-cmake +# ***************************************************************************** +# +# INFORMATION / HELP +# +############################################################################### +# OPTIONS # +############################################################################### +# +# PLATFORM: (default "OS64") +# OS = Build for iPhoneOS. +# OS64 = Build for arm64 iphoneOS. +# OS64COMBINED = Build for arm64 x86_64 iphoneOS + iphoneOS Simulator. Combined into FAT STATIC lib (only supported on 3.14+ of CMake with "-G Xcode" argument in combination with the "cmake --install" CMake build step) +# SIMULATOR = Build for x86 i386 iphoneOS Simulator. +# SIMULATOR64 = Build for x86_64 iphoneOS Simulator. +# SIMULATORARM64 = Build for arm64 iphoneOS Simulator. +# TVOS = Build for arm64 tvOS. +# TVOSCOMBINED = Build for arm64 x86_64 tvOS + tvOS Simulator. Combined into FAT STATIC lib (only supported on 3.14+ of CMake with "-G Xcode" argument in combination with the "cmake --install" CMake build step) +# SIMULATOR_TVOS = Build for x86_64 tvOS Simulator. +# WATCHOS = Build for armv7k arm64_32 for watchOS. +# WATCHOSCOMBINED = Build for armv7k arm64_32 x86_64 watchOS + watchOS Simulator. Combined into FAT STATIC lib (only supported on 3.14+ of CMake with "-G Xcode" argument in combination with the "cmake --install" CMake build step) +# SIMULATOR_WATCHOS = Build for x86_64 for watchOS Simulator. +# MAC = Build for x86_64 macOS. +# MAC_ARM64 = Build for Apple Silicon macOS. +# MAC_CATALYST = Build for x86_64 macOS with Catalyst support (iOS toolchain on macOS). +# Note: The build argument "MACOSX_DEPLOYMENT_TARGET" can be used to control min-version of macOS +# MAC_CATALYST_ARM64 = Build for Apple Silicon macOS with Catalyst support (iOS toolchain on macOS). +# Note: The build argument "MACOSX_DEPLOYMENT_TARGET" can be used to control min-version of macOS +# +# CMAKE_OSX_SYSROOT: Path to the SDK to use. By default this is +# automatically determined from PLATFORM and xcodebuild, but +# can also be manually specified (although this should not be required). +# +# CMAKE_DEVELOPER_ROOT: Path to the Developer directory for the platform +# being compiled for. By default this is automatically determined from +# CMAKE_OSX_SYSROOT, but can also be manually specified (although this should +# not be required). +# +# DEPLOYMENT_TARGET: Minimum SDK version to target. Default 2.0 on watchOS and 9.0 on tvOS+iOS +# +# NAMED_LANGUAGE_SUPPORT: +# ON (default) = Will require "enable_language(OBJC) and/or enable_language(OBJCXX)" for full OBJC|OBJCXX support +# OFF = Will embed the OBJC and OBJCXX flags into the CMAKE_C_FLAGS and CMAKE_CXX_FLAGS (legacy behaviour, CMake version < 3.16) +# +# ENABLE_BITCODE: (ON|OFF) Enables or disables bitcode support. Default ON +# +# ENABLE_ARC: (ON|OFF) Enables or disables ARC support. Default ON (ARC enabled by default) +# +# ENABLE_VISIBILITY: (ON|OFF) Enables or disables symbol visibility support. Default OFF (visibility hidden by default) +# +# ENABLE_STRICT_TRY_COMPILE: (ON|OFF) Enables or disables strict try_compile() on all Check* directives (will run linker +# to actually check if linking is possible). Default OFF (will set CMAKE_TRY_COMPILE_TARGET_TYPE to STATIC_LIBRARY) +# +# ARCHS: (armv7 armv7s armv7k arm64 arm64_32 i386 x86_64) If specified, will override the default architectures for the given PLATFORM +# OS = armv7 armv7s arm64 (if applicable) +# OS64 = arm64 (if applicable) +# SIMULATOR = i386 +# SIMULATOR64 = x86_64 +# SIMULATORARM64 = arm64 +# TVOS = arm64 +# SIMULATOR_TVOS = x86_64 (i386 has since long been deprecated) +# WATCHOS = armv7k arm64_32 (if applicable) +# SIMULATOR_WATCHOS = x86_64 (i386 has since long been deprecated) +# MAC = x86_64 +# MAC_ARM64 = arm64 +# MAC_CATALYST = x86_64 +# MAC_CATALYST_ARM64 = arm64 +# +# NOTE: When manually specifying ARCHS, put a semi-colon between the entries. E.g., -DARCHS="armv7;arm64" +# +############################################################################### +# END OPTIONS # +############################################################################### +# +# This toolchain defines the following properties (available via get_property()) for use externally: +# +# PLATFORM: The currently targeted platform. +# XCODE_VERSION: Version number (not including Build version) of Xcode detected. +# SDK_VERSION: Version of SDK being used. +# OSX_ARCHITECTURES: Architectures being compiled for (generated from PLATFORM). +# APPLE_TARGET_TRIPLE: Used by autoconf build systems. NOTE: If "ARCHS" are overridden, this will *NOT* be set! +# +# This toolchain defines the following macros for use externally: +# +# set_xcode_property (TARGET XCODE_PROPERTY XCODE_VALUE XCODE_VARIANT) +# A convenience macro for setting xcode specific properties on targets. +# Available variants are: All, Release, RelWithDebInfo, Debug, MinSizeRel +# example: set_xcode_property (myioslib IPHONEOS_DEPLOYMENT_TARGET "3.1" "all"). +# +# find_host_package (PROGRAM ARGS) +# A macro used to find executable programs on the host system, not within the +# environment. Thanks to the android-cmake project for providing the +# command. +# + +cmake_minimum_required(VERSION 3.8.0) + +# CMake invokes the toolchain file twice during the first build, but only once during subsequent rebuilds. +if(DEFINED ENV{_IOS_TOOLCHAIN_HAS_RUN}) + return() +endif() +set(ENV{_IOS_TOOLCHAIN_HAS_RUN} true) + +# List of supported platform values +list(APPEND _supported_platforms + "OS" "OS64" "OS64COMBINED" "SIMULATOR" "SIMULATOR64" "SIMULATORARM64" + "TVOS" "TVOSCOMBINED" "SIMULATOR_TVOS" + "WATCHOS" "WATCHOSCOMBINED" "SIMULATOR_WATCHOS" + "MAC" "MAC_ARM64" + "MAC_CATALYST" "MAC_CATALYST_ARM64") + +# Cache what generator is used +set(USED_CMAKE_GENERATOR "${CMAKE_GENERATOR}") + +# Check if using a CMake version capable of building combined FAT builds (simulator and target slices combined in one static lib) +if(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.14") + set(MODERN_CMAKE YES) +endif() + +# Get the Xcode version being used. +# Problem: CMake runs toolchain files multiple times, but can't read cache variables on some runs. +# Workaround: On first run (in which cache variables are always accessible), set an intermediary environment variable. +# +# NOTE: This pattern is used i many places in this toolchain to speed up checks of all sorts +if(DEFINED XCODE_VERSION_INT) + # Environment variables are always preserved. + set(ENV{_XCODE_VERSION_INT} "${XCODE_VERSION_INT}") +elseif(DEFINED ENV{_XCODE_VERSION_INT}) + set(XCODE_VERSION_INT "$ENV{_XCODE_VERSION_INT}") +elseif(NOT DEFINED XCODE_VERSION_INT) + find_program(XCODEBUILD_EXECUTABLE xcodebuild) + if(NOT XCODEBUILD_EXECUTABLE) + message(FATAL_ERROR "xcodebuild not found. Please install either the standalone commandline tools or Xcode.") + endif() + execute_process(COMMAND ${XCODEBUILD_EXECUTABLE} -version + OUTPUT_VARIABLE XCODE_VERSION_INT + ERROR_QUIET + OUTPUT_STRIP_TRAILING_WHITESPACE) + string(REGEX MATCH "Xcode [0-9\\.]+" XCODE_VERSION_INT "${XCODE_VERSION_INT}") + string(REGEX REPLACE "Xcode ([0-9\\.]+)" "\\1" XCODE_VERSION_INT "${XCODE_VERSION_INT}") + set(XCODE_VERSION_INT "${XCODE_VERSION_INT}" CACHE INTERNAL "") +endif() + +# Assuming that xcode 12.0 is installed you most probably have ios sdk 14.0 or later installed (tested on Big Sur) +# if you don't set a deployment target it will be set the way you only get 64-bit builds +if(NOT DEFINED DEPLOYMENT_TARGET AND XCODE_VERSION_INT VERSION_GREATER 12.0) + # Temporarily fix the arm64 issues in CMake install-combined by excluding arm64 for simulator builds (needed for Apple Silicon...) + set(CMAKE_XCODE_ATTRIBUTE_EXCLUDED_ARCHS[sdk=iphonesimulator*] "arm64") +endif() + +# Check if the platform variable is set +if(DEFINED PLATFORM) + # Environment variables are always preserved. + set(ENV{_PLATFORM} "${PLATFORM}") +elseif(DEFINED ENV{_PLATFORM}) + set(PLATFORM "$ENV{_PLATFORM}") +elseif(NOT DEFINED PLATFORM) + message(FATAL_ERROR "PLATFORM argument not set. Bailing configure since I don't know what target you want to build for!") +endif () + +if(PLATFORM MATCHES ".*COMBINED" AND NOT CMAKE_GENERATOR MATCHES "Xcode") + message(FATAL_ERROR "The combined builds support requires Xcode to be used as generator via '-G Xcode' command-line argument in CMake") +endif() + +# Safeguard that the platform value is set and is one of the supported values +list(FIND _supported_platforms ${PLATFORM} contains_PLATFORM) +if("${contains_PLATFORM}" EQUAL "-1") + string(REPLACE ";" "\n * " _supported_platforms_formatted "${_supported_platforms}") + message(FATAL_ERROR " Invalid PLATFORM specified! Current value: ${PLATFORM}.\n" + " Supported PLATFORM values: \n * ${_supported_platforms_formatted}") +endif() + +# Check if Apple Silicon is supported +if(PLATFORM MATCHES "^(MAC_ARM64)$|^(MAC_CATALYST_ARM64)$" AND ${CMAKE_VERSION} VERSION_LESS "3.19.5") + message(FATAL_ERROR "Apple Silicon builds requires a minimum of CMake 3.19.5") +endif() + +# Touch toolchain variable to suppress "unused variable" warning. +# This happens if CMake is invoked with the same command line the second time. +if(CMAKE_TOOLCHAIN_FILE) +endif() + +# Fix for PThread library not in path +set(CMAKE_THREAD_LIBS_INIT "-lpthread") +set(CMAKE_HAVE_THREADS_LIBRARY 1) +set(CMAKE_USE_WIN32_THREADS_INIT 0) +set(CMAKE_USE_PTHREADS_INIT 1) + +# Specify named language support defaults. +if(NOT DEFINED NAMED_LANGUAGE_SUPPORT AND ${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.16") + set(NAMED_LANGUAGE_SUPPORT ON) + message(STATUS "[DEFAULTS] Using explicit named language support! E.g., enable_language(CXX) is needed in the project files.") +elseif(NOT DEFINED NAMED_LANGUAGE_SUPPORT AND ${CMAKE_VERSION} VERSION_LESS "3.16") + set(NAMED_LANGUAGE_SUPPORT OFF) + message(STATUS "[DEFAULTS] Disabling explicit named language support. Falling back to legacy behaviour.") +elseif(DEFINED NAMED_LANGUAGE_SUPPORT AND ${CMAKE_VERSION} VERSION_LESS "3.16") + message(FATAL_ERROR "CMake named language support for OBJC and OBJCXX was added in CMake 3.16.") +endif() +set(NAMED_LANGUAGE_SUPPORT_INT ${NAMED_LANGUAGE_SUPPORT} CACHE BOOL + "Whether or not to enable explicit named language support" FORCE) + +# Specify minimum version of deployment target. +if(NOT DEFINED DEPLOYMENT_TARGET) + if (PLATFORM MATCHES "WATCHOS") + # Unless specified, SDK version 4.0 is used by default as minimum target version (watchOS). + set(DEPLOYMENT_TARGET "4.0") + elseif(PLATFORM STREQUAL "MAC") + # Unless specified, SDK version 10.13 (High sierra) is used by default as minimum target version (macos). + set(DEPLOYMENT_TARGET "10.13") + elseif(PLATFORM STREQUAL "MAC_ARM64") + # Unless specified, SDK version 11.0 (Big Sur) is used by default as minimum target version (macos on arm). + set(DEPLOYMENT_TARGET "11.0") + elseif(PLATFORM STREQUAL "MAC_CATALYST" OR PLATFORM STREQUAL "MAC_CATALYST_ARM64") + # Unless specified, SDK version 13.0 is used by default as minimum target version (mac catalyst minimum requirement). + set(DEPLOYMENT_TARGET "13.1") + else() + # Unless specified, SDK version 11.0 is used by default as minimum target version (iOS, tvOS). + set(DEPLOYMENT_TARGET "11.0") + endif() + message(STATUS "[DEFAULTS] Using the default min-version since DEPLOYMENT_TARGET not provided!") +elseif(DEFINED DEPLOYMENT_TARGET AND PLATFORM MATCHES "^MAC_CATALYST" AND ${DEPLOYMENT_TARGET} VERSION_LESS "13.1") + message(FATAL_ERROR "Mac Catalyst builds requires a minimum deployment target of 13.1!") +endif() + +# Store the DEPLOYMENT_TARGET in the cache +set(DEPLOYMENT_TARGET "${DEPLOYMENT_TARGET}" CACHE INTERNAL "") + +# Handle the case where we are targeting iOS and a version above 10.3.4 (32-bit support dropped officially) +if(PLATFORM STREQUAL "OS" AND DEPLOYMENT_TARGET VERSION_GREATER_EQUAL 10.3.4) + set(PLATFORM "OS64") + message(STATUS "Targeting minimum SDK version ${DEPLOYMENT_TARGET}. Dropping 32-bit support.") +elseif(PLATFORM STREQUAL "SIMULATOR" AND DEPLOYMENT_TARGET VERSION_GREATER_EQUAL 10.3.4) + set(PLATFORM "SIMULATOR64") + message(STATUS "Targeting minimum SDK version ${DEPLOYMENT_TARGET}. Dropping 32-bit support.") +endif() + +set(PLATFORM_INT "${PLATFORM}") + +if(DEFINED ARCHS) + string(REPLACE ";" "-" ARCHS_SPLIT "${ARCHS}") +endif() + +# Determine the platform name and architectures for use in xcodebuild commands +# from the specified PLATFORM_INT name. +if(PLATFORM_INT STREQUAL "OS") + set(SDK_NAME iphoneos) + if(NOT ARCHS) + set(ARCHS armv7 armv7s arm64) + set(APPLE_TARGET_TRIPLE_INT arm-apple-ios${DEPLOYMENT_TARGET}) + else() + set(APPLE_TARGET_TRIPLE_INT ${ARCHS_SPLIT}-apple-ios${DEPLOYMENT_TARGET}) + endif() +elseif(PLATFORM_INT STREQUAL "OS64") + set(SDK_NAME iphoneos) + if(NOT ARCHS) + if (XCODE_VERSION_INT VERSION_GREATER 10.0) + set(ARCHS arm64) # FIXME: Add arm64e when Apple have fixed the integration issues with it, libarclite_iphoneos.a is currently missung bitcode markers for example + else() + set(ARCHS arm64) + endif() + set(APPLE_TARGET_TRIPLE_INT aarch64-apple-ios${DEPLOYMENT_TARGET}) + else() + set(APPLE_TARGET_TRIPLE_INT ${ARCHS_SPLIT}-apple-ios${DEPLOYMENT_TARGET}) + endif() +elseif(PLATFORM_INT STREQUAL "OS64COMBINED") + set(SDK_NAME iphoneos) + if(MODERN_CMAKE) + if(NOT ARCHS) + if (XCODE_VERSION_INT VERSION_GREATER 10.0) + set(ARCHS arm64 x86_64) # FIXME: Add arm64e when Apple have fixed the integration issues with it, libarclite_iphoneos.a is currently missung bitcode markers for example + set(CMAKE_XCODE_ATTRIBUTE_ARCHS[sdk=iphoneos*] "arm64") + set(CMAKE_XCODE_ATTRIBUTE_ARCHS[sdk=iphonesimulator*] "x86_64") + set(CMAKE_XCODE_ATTRIBUTE_VALID_ARCHS[sdk=iphoneos*] "arm64") + set(CMAKE_XCODE_ATTRIBUTE_VALID_ARCHS[sdk=iphonesimulator*] "x86_64") + else() + set(ARCHS arm64 x86_64) + set(CMAKE_XCODE_ATTRIBUTE_ARCHS[sdk=iphoneos*] "arm64") + set(CMAKE_XCODE_ATTRIBUTE_ARCHS[sdk=iphonesimulator*] "x86_64") + set(CMAKE_XCODE_ATTRIBUTE_VALID_ARCHS[sdk=iphoneos*] "arm64") + set(CMAKE_XCODE_ATTRIBUTE_VALID_ARCHS[sdk=iphonesimulator*] "x86_64") + endif() + set(APPLE_TARGET_TRIPLE_INT aarch64-x86_64-apple-ios${DEPLOYMENT_TARGET}) + else() + set(APPLE_TARGET_TRIPLE_INT ${ARCHS_SPLIT}-apple-ios${DEPLOYMENT_TARGET}) + endif() + else() + message(FATAL_ERROR "Please make sure that you are running CMake 3.14+ to make the OS64COMBINED setting work") + endif() +elseif(PLATFORM_INT STREQUAL "SIMULATOR") + set(SDK_NAME iphonesimulator) + if(NOT ARCHS) + set(ARCHS i386) + set(APPLE_TARGET_TRIPLE_INT i386-apple-ios${DEPLOYMENT_TARGET}-simulator) + else() + set(APPLE_TARGET_TRIPLE_INT ${ARCHS_SPLIT}-apple-ios${DEPLOYMENT_TARGET}-simulator) + endif() + message(DEPRECATION "SIMULATOR IS DEPRECATED. Consider using SIMULATOR64 instead.") +elseif(PLATFORM_INT STREQUAL "SIMULATOR64") + set(SDK_NAME iphonesimulator) + if(NOT ARCHS) + set(ARCHS x86_64) + set(APPLE_TARGET_TRIPLE_INT x86_64-apple-ios${DEPLOYMENT_TARGET}-simulator) + else() + set(APPLE_TARGET_TRIPLE_INT ${ARCHS_SPLIT}-apple-ios${DEPLOYMENT_TARGET}-simulator) + endif() +elseif(PLATFORM_INT STREQUAL "SIMULATORARM64") + set(SDK_NAME iphonesimulator) + if(NOT ARCHS) + set(ARCHS arm64) + set(APPLE_TARGET_TRIPLE_INT aarch64-apple-ios${DEPLOYMENT_TARGET}-simulator) + else() + set(APPLE_TARGET_TRIPLE_INT ${ARCHS_SPLIT}-apple-ios${DEPLOYMENT_TARGET}-simulator) + endif() +elseif(PLATFORM_INT STREQUAL "TVOS") + set(SDK_NAME appletvos) + if(NOT ARCHS) + set(ARCHS arm64) + set(APPLE_TARGET_TRIPLE_INT aarch64-apple-tvos${DEPLOYMENT_TARGET}) + else() + set(APPLE_TARGET_TRIPLE_INT ${ARCHS_SPLIT}-apple-tvos${DEPLOYMENT_TARGET}) + endif() +elseif (PLATFORM_INT STREQUAL "TVOSCOMBINED") + set(SDK_NAME appletvos) + if(MODERN_CMAKE) + if(NOT ARCHS) + set(ARCHS arm64 x86_64) + set(APPLE_TARGET_TRIPLE_INT aarch64-x86_64-apple-tvos${DEPLOYMENT_TARGET}) + set(CMAKE_XCODE_ATTRIBUTE_ARCHS[sdk=appletvos*] "arm64") + set(CMAKE_XCODE_ATTRIBUTE_ARCHS[sdk=appletvsimulator*] "x86_64") + set(CMAKE_XCODE_ATTRIBUTE_VALID_ARCHS[sdk=appletvos*] "arm64") + set(CMAKE_XCODE_ATTRIBUTE_VALID_ARCHS[sdk=appletvsimulator*] "x86_64") + else() + set(APPLE_TARGET_TRIPLE_INT ${ARCHS_SPLIT}-apple-tvos${DEPLOYMENT_TARGET}) + endif() + else() + message(FATAL_ERROR "Please make sure that you are running CMake 3.14+ to make the TVOSCOMBINED setting work") + endif() +elseif(PLATFORM_INT STREQUAL "SIMULATOR_TVOS") + set(SDK_NAME appletvsimulator) + if(NOT ARCHS) + set(ARCHS x86_64) + set(APPLE_TARGET_TRIPLE_INT x86_64-apple-tvos${DEPLOYMENT_TARGET}-simulator) + else() + set(APPLE_TARGET_TRIPLE_INT ${ARCHS_SPLIT}-apple-tvos${DEPLOYMENT_TARGET}-simulator) + endif() +elseif(PLATFORM_INT STREQUAL "WATCHOS") + set(SDK_NAME watchos) + if(NOT ARCHS) + if (XCODE_VERSION_INT VERSION_GREATER 10.0) + set(ARCHS armv7k arm64_32) + set(APPLE_TARGET_TRIPLE_INT aarch64_32-apple-watchos${DEPLOYMENT_TARGET}) + else() + set(ARCHS armv7k) + set(APPLE_TARGET_TRIPLE_INT arm-apple-watchos${DEPLOYMENT_TARGET}) + endif() + else() + set(APPLE_TARGET_TRIPLE_INT ${ARCHS_SPLIT}-apple-watchos${DEPLOYMENT_TARGET}) + endif() +elseif(PLATFORM_INT STREQUAL "WATCHOSCOMBINED") + set(SDK_NAME watchos) + if(MODERN_CMAKE) + if(NOT ARCHS) + if (XCODE_VERSION_INT VERSION_GREATER 10.0) + set(ARCHS armv7k arm64_32 i386) + set(APPLE_TARGET_TRIPLE_INT aarch64_32-i386-apple-watchos${DEPLOYMENT_TARGET}) + set(CMAKE_XCODE_ATTRIBUTE_ARCHS[sdk=watchos*] "armv7k arm64_32") + set(CMAKE_XCODE_ATTRIBUTE_ARCHS[sdk=watchsimulator*] "i386") + set(CMAKE_XCODE_ATTRIBUTE_VALID_ARCHS[sdk=watchos*] "armv7k arm64_32") + set(CMAKE_XCODE_ATTRIBUTE_VALID_ARCHS[sdk=watchsimulator*] "i386") + else() + set(ARCHS armv7k i386) + set(APPLE_TARGET_TRIPLE_INT arm-i386-apple-watchos${DEPLOYMENT_TARGET}) + set(CMAKE_XCODE_ATTRIBUTE_ARCHS[sdk=watchos*] "armv7k") + set(CMAKE_XCODE_ATTRIBUTE_ARCHS[sdk=watchsimulator*] "i386") + set(CMAKE_XCODE_ATTRIBUTE_VALID_ARCHS[sdk=watchos*] "armv7k") + set(CMAKE_XCODE_ATTRIBUTE_VALID_ARCHS[sdk=watchsimulator*] "i386") + endif() + else() + set(APPLE_TARGET_TRIPLE_INT ${ARCHS_SPLIT}-apple-watchos${DEPLOYMENT_TARGET}) + endif() + else() + message(FATAL_ERROR "Please make sure that you are running CMake 3.14+ to make the WATCHOSCOMBINED setting work") + endif() +elseif(PLATFORM_INT STREQUAL "SIMULATOR_WATCHOS") + set(SDK_NAME watchsimulator) + if(NOT ARCHS) + set(ARCHS i386) + set(APPLE_TARGET_TRIPLE_INT i386-apple-watchos${DEPLOYMENT_TARGET}-simulator) + else() + set(APPLE_TARGET_TRIPLE_INT ${ARCHS_SPLIT}-apple-watchos${DEPLOYMENT_TARGET}-simulator) + endif() +elseif(PLATFORM_INT STREQUAL "MAC" OR PLATFORM_INT STREQUAL "MAC_CATALYST") + set(SDK_NAME macosx) + if(NOT ARCHS) + set(ARCHS x86_64) + endif() + string(REPLACE ";" "-" ARCHS_SPLIT "${ARCHS}") + if(PLATFORM_INT STREQUAL "MAC") + set(APPLE_TARGET_TRIPLE_INT ${ARCHS_SPLIT}-apple-macosx${DEPLOYMENT_TARGET}) + elseif(PLATFORM_INT STREQUAL "MAC_CATALYST") + set(APPLE_TARGET_TRIPLE_INT ${ARCHS_SPLIT}-apple-ios${DEPLOYMENT_TARGET}-macabi) + endif() +elseif(PLATFORM_INT MATCHES "^(MAC_ARM64)$|^(MAC_CATALYST_ARM64)$") + set(SDK_NAME macosx) + if(NOT ARCHS) + set(ARCHS arm64) + endif() + string(REPLACE ";" "-" ARCHS_SPLIT "${ARCHS}") + if(PLATFORM_INT STREQUAL "MAC_ARM64") + set(APPLE_TARGET_TRIPLE_INT ${ARCHS_SPLIT}-apple-macosx${DEPLOYMENT_TARGET}) + elseif(PLATFORM_INT STREQUAL "MAC_CATALYST_ARM64") + set(APPLE_TARGET_TRIPLE_INT ${ARCHS_SPLIT}-apple-ios${DEPLOYMENT_TARGET}-macabi) + endif() +else() + message(FATAL_ERROR "Invalid PLATFORM: ${PLATFORM_INT}") +endif() + +string(REPLACE ";" " " ARCHS_SPACED "${ARCHS}") + +if(MODERN_CMAKE AND PLATFORM_INT MATCHES ".*COMBINED" AND NOT CMAKE_GENERATOR MATCHES "Xcode") + message(FATAL_ERROR "The COMBINED options only work with Xcode generator, -G Xcode") +endif() + +if(CMAKE_GENERATOR MATCHES "Xcode" AND PLATFORM_INT MATCHES "^MAC_CATALYST") + set(CMAKE_XCODE_ATTRIBUTE_CLANG_CXX_LIBRARY "libc++") + set(CMAKE_XCODE_ATTRIBUTE_SUPPORTED_PLATFORMS "macosx") + set(CMAKE_XCODE_EFFECTIVE_PLATFORMS "-maccatalyst") + if(NOT DEFINED MACOSX_DEPLOYMENT_TARGET) + set(CMAKE_XCODE_ATTRIBUTE_MACOSX_DEPLOYMENT_TARGET "10.15") + else() + set(CMAKE_XCODE_ATTRIBUTE_MACOSX_DEPLOYMENT_TARGET "${MACOSX_DEPLOYMENT_TARGET}") + endif() +elseif(CMAKE_GENERATOR MATCHES "Xcode") + set(CMAKE_XCODE_ATTRIBUTE_CLANG_CXX_LIBRARY "libc++") + set(CMAKE_XCODE_ATTRIBUTE_IPHONEOS_DEPLOYMENT_TARGET "${DEPLOYMENT_TARGET}") + if(NOT PLATFORM_INT MATCHES ".*COMBINED") + set(CMAKE_XCODE_ATTRIBUTE_ARCHS[sdk=${SDK_NAME}*] "${ARCHS_SPACED}") + set(CMAKE_XCODE_ATTRIBUTE_VALID_ARCHS[sdk=${SDK_NAME}*] "${ARCHS_SPACED}") + endif() +endif() + +# If user did not specify the SDK root to use, then query xcodebuild for it. +if(DEFINED CMAKE_OSX_SYSROOT_INT) + # Environment variables are always preserved. + set(ENV{_CMAKE_OSX_SYSROOT_INT} "${CMAKE_OSX_SYSROOT_INT}") +elseif(DEFINED ENV{_CMAKE_OSX_SYSROOT_INT}) + set(CMAKE_OSX_SYSROOT_INT "$ENV{_CMAKE_OSX_SYSROOT_INT}") +elseif(NOT DEFINED CMAKE_OSX_SYSROOT_INT) + execute_process(COMMAND ${XCODEBUILD_EXECUTABLE} -version -sdk ${SDK_NAME} Path + OUTPUT_VARIABLE CMAKE_OSX_SYSROOT_INT + ERROR_QUIET + OUTPUT_STRIP_TRAILING_WHITESPACE) +endif() + +if (NOT DEFINED CMAKE_OSX_SYSROOT_INT AND NOT DEFINED CMAKE_OSX_SYSROOT) + message(SEND_ERROR "Please make sure that Xcode is installed and that the toolchain" + "is pointing to the correct path. Please run:" + "sudo xcode-select -s /Applications/Xcode.app/Contents/Developer" + "and see if that fixes the problem for you.") + message(FATAL_ERROR "Invalid CMAKE_OSX_SYSROOT: ${CMAKE_OSX_SYSROOT} " + "does not exist.") +elseif(DEFINED CMAKE_OSX_SYSROOT_INT) + set(CMAKE_OSX_SYSROOT_INT "${CMAKE_OSX_SYSROOT_INT}" CACHE INTERNAL "") + # Specify the location or name of the platform SDK to be used in CMAKE_OSX_SYSROOT. + set(CMAKE_OSX_SYSROOT "${CMAKE_OSX_SYSROOT_INT}" CACHE INTERNAL "") +endif() + +# Use bitcode or not +if(NOT DEFINED ENABLE_BITCODE AND NOT ARCHS MATCHES "((^|;|, )(i386|x86_64))+") + # Unless specified, enable bitcode support by default + message(STATUS "[DEFAULTS] Enabling bitcode support by default. ENABLE_BITCODE not provided!") + set(ENABLE_BITCODE ON) +elseif(NOT DEFINED ENABLE_BITCODE) + message(STATUS "[DEFAULTS] Disabling bitcode support by default on simulators. ENABLE_BITCODE not provided for override!") + set(ENABLE_BITCODE OFF) +endif() +set(ENABLE_BITCODE_INT ${ENABLE_BITCODE} CACHE BOOL + "Whether or not to enable bitcode" FORCE) +# Use ARC or not +if(NOT DEFINED ENABLE_ARC) + # Unless specified, enable ARC support by default + set(ENABLE_ARC ON) + message(STATUS "[DEFAULTS] Enabling ARC support by default. ENABLE_ARC not provided!") +endif() +set(ENABLE_ARC_INT ${ENABLE_ARC} CACHE BOOL "Whether or not to enable ARC" FORCE) +# Use hidden visibility or not +if(NOT DEFINED ENABLE_VISIBILITY) + # Unless specified, disable symbols visibility by default + set(ENABLE_VISIBILITY OFF) + message(STATUS "[DEFAULTS] Hiding symbols visibility by default. ENABLE_VISIBILITY not provided!") +endif() +set(ENABLE_VISIBILITY_INT ${ENABLE_VISIBILITY} CACHE BOOL "Whether or not to hide symbols from the dynamic linker (-fvisibility=hidden)" FORCE) +# Set strict compiler checks or not +if(NOT DEFINED ENABLE_STRICT_TRY_COMPILE) + # Unless specified, disable strict try_compile() + set(ENABLE_STRICT_TRY_COMPILE OFF) + message(STATUS "[DEFAULTS] Using NON-strict compiler checks by default. ENABLE_STRICT_TRY_COMPILE not provided!") +endif() +set(ENABLE_STRICT_TRY_COMPILE_INT ${ENABLE_STRICT_TRY_COMPILE} CACHE BOOL + "Whether or not to use strict compiler checks" FORCE) + +# Get the SDK version information. +if(DEFINED SDK_VERSION) + # Environment variables are always preserved. + set(ENV{_SDK_VERSION} "${SDK_VERSION}") +elseif(DEFINED ENV{_SDK_VERSION}) + set(SDK_VERSION "$ENV{_SDK_VERSION}") +elseif(NOT DEFINED SDK_VERSION) + execute_process(COMMAND ${XCODEBUILD_EXECUTABLE} -sdk ${CMAKE_OSX_SYSROOT_INT} -version SDKVersion + OUTPUT_VARIABLE SDK_VERSION + ERROR_QUIET + OUTPUT_STRIP_TRAILING_WHITESPACE) +endif() + +# Find the Developer root for the specific iOS platform being compiled for +# from CMAKE_OSX_SYSROOT. Should be ../../ from SDK specified in +# CMAKE_OSX_SYSROOT. There does not appear to be a direct way to obtain +# this information from xcrun or xcodebuild. +if (NOT DEFINED CMAKE_DEVELOPER_ROOT AND NOT CMAKE_GENERATOR MATCHES "Xcode") + get_filename_component(PLATFORM_SDK_DIR ${CMAKE_OSX_SYSROOT_INT} PATH) + get_filename_component(CMAKE_DEVELOPER_ROOT ${PLATFORM_SDK_DIR} PATH) + if (NOT EXISTS "${CMAKE_DEVELOPER_ROOT}") + message(FATAL_ERROR "Invalid CMAKE_DEVELOPER_ROOT: ${CMAKE_DEVELOPER_ROOT} does not exist.") + endif() +endif() + +# Find the C & C++ compilers for the specified SDK. +if(DEFINED CMAKE_C_COMPILER) + # Environment variables are always preserved. + set(ENV{_CMAKE_C_COMPILER} "${CMAKE_C_COMPILER}") +elseif(DEFINED ENV{_CMAKE_C_COMPILER}) + set(CMAKE_C_COMPILER "$ENV{_CMAKE_C_COMPILER}") + set(CMAKE_ASM_COMPILER ${CMAKE_C_COMPILER}) +elseif(NOT DEFINED CMAKE_C_COMPILER) + execute_process(COMMAND xcrun -sdk ${CMAKE_OSX_SYSROOT_INT} -find clang + OUTPUT_VARIABLE CMAKE_C_COMPILER + ERROR_QUIET + OUTPUT_STRIP_TRAILING_WHITESPACE) + set(CMAKE_ASM_COMPILER ${CMAKE_C_COMPILER}) +endif() +if(DEFINED CMAKE_CXX_COMPILER) + # Environment variables are always preserved. + set(ENV{_CMAKE_CXX_COMPILER} "${CMAKE_CXX_COMPILER}") +elseif(DEFINED ENV{_CMAKE_CXX_COMPILER}) + set(CMAKE_CXX_COMPILER "$ENV{_CMAKE_CXX_COMPILER}") +elseif(NOT DEFINED CMAKE_CXX_COMPILER) + execute_process(COMMAND xcrun -sdk ${CMAKE_OSX_SYSROOT_INT} -find clang++ + OUTPUT_VARIABLE CMAKE_CXX_COMPILER + ERROR_QUIET + OUTPUT_STRIP_TRAILING_WHITESPACE) +endif() +# Find (Apple's) libtool. +if(DEFINED BUILD_LIBTOOL) + # Environment variables are always preserved. + set(ENV{_BUILD_LIBTOOL} "${BUILD_LIBTOOL}") +elseif(DEFINED ENV{_BUILD_LIBTOOL}) + set(BUILD_LIBTOOL "$ENV{_BUILD_LIBTOOL}") +elseif(NOT DEFINED BUILD_LIBTOOL) + execute_process(COMMAND xcrun -sdk ${CMAKE_OSX_SYSROOT_INT} -find libtool + OUTPUT_VARIABLE BUILD_LIBTOOL + ERROR_QUIET + OUTPUT_STRIP_TRAILING_WHITESPACE) +endif() +# Find the toolchain's provided install_name_tool if none is found on the host +if(DEFINED CMAKE_INSTALL_NAME_TOOL) + # Environment variables are always preserved. + set(ENV{_CMAKE_INSTALL_NAME_TOOL} "${CMAKE_INSTALL_NAME_TOOL}") +elseif(DEFINED ENV{_CMAKE_INSTALL_NAME_TOOL}) + set(CMAKE_INSTALL_NAME_TOOL "$ENV{_CMAKE_INSTALL_NAME_TOOL}") +elseif(NOT DEFINED CMAKE_INSTALL_NAME_TOOL) + execute_process(COMMAND xcrun -sdk ${CMAKE_OSX_SYSROOT_INT} -find install_name_tool + OUTPUT_VARIABLE CMAKE_INSTALL_NAME_TOOL_INT + ERROR_QUIET + OUTPUT_STRIP_TRAILING_WHITESPACE) + set(CMAKE_INSTALL_NAME_TOOL ${CMAKE_INSTALL_NAME_TOOL_INT} CACHE INTERNAL "") +endif() + +# Configure libtool to be used instead of ar + ranlib to build static libraries. +# This is required on Xcode 7+, but should also work on previous versions of +# Xcode. +get_property(languages GLOBAL PROPERTY ENABLED_LANGUAGES) +foreach(lang ${languages}) + set(CMAKE_${lang}_CREATE_STATIC_LIBRARY "${BUILD_LIBTOOL} -static -o " CACHE INTERNAL "") +endforeach() + +# CMake 3.14+ support building for iOS, watchOS and tvOS out of the box. +if(MODERN_CMAKE) + if(SDK_NAME MATCHES "iphone") + set(CMAKE_SYSTEM_NAME iOS) + elseif(SDK_NAME MATCHES "macosx") + set(CMAKE_SYSTEM_NAME Darwin) + elseif(SDK_NAME MATCHES "appletv") + set(CMAKE_SYSTEM_NAME tvOS) + elseif(SDK_NAME MATCHES "watch") + set(CMAKE_SYSTEM_NAME watchOS) + endif() + # Provide flags for a combined FAT library build on newer CMake versions + if(PLATFORM_INT MATCHES ".*COMBINED") + set(CMAKE_XCODE_ATTRIBUTE_ONLY_ACTIVE_ARCH "NO") + set(CMAKE_IOS_INSTALL_COMBINED YES) + endif() +elseif(NOT DEFINED CMAKE_SYSTEM_NAME AND ${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.10") + # Legacy code path prior to CMake 3.14 or fallback if no CMAKE_SYSTEM_NAME specified + set(CMAKE_SYSTEM_NAME iOS) +elseif(NOT DEFINED CMAKE_SYSTEM_NAME) + # Legacy code path prior to CMake 3.14 or fallback if no CMAKE_SYSTEM_NAME specified + set(CMAKE_SYSTEM_NAME Darwin) +endif() +# Standard settings. +set(CMAKE_SYSTEM_VERSION ${SDK_VERSION} CACHE INTERNAL "") +set(UNIX ON CACHE BOOL "") +set(APPLE ON CACHE BOOL "") +if(PLATFORM STREQUAL "MAC" OR PLATFORM STREQUAL "MAC_ARM64") + set(IOS OFF CACHE BOOL "") + set(MACOS ON CACHE BOOL "") +elseif(PLATFORM STREQUAL "MAC_CATALYST" OR PLATFORM STREQUAL "MAC_CATALYST_ARM64") + set(IOS ON CACHE BOOL "") + set(MACOS ON CACHE BOOL "") +else() + set(IOS ON CACHE BOOL "") +endif() +set(CMAKE_AR ar CACHE FILEPATH "" FORCE) +set(CMAKE_RANLIB ranlib CACHE FILEPATH "" FORCE) +set(CMAKE_STRIP strip CACHE FILEPATH "" FORCE) +# Set the architectures for which to build. +set(CMAKE_OSX_ARCHITECTURES ${ARCHS} CACHE INTERNAL "") +# Change the type of target generated for try_compile() so it'll work when cross-compiling, weak compiler checks +if(NOT ENABLE_STRICT_TRY_COMPILE_INT) + set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY) +endif() +# All iOS/Darwin specific settings - some may be redundant. +set(CMAKE_MACOSX_BUNDLE YES) +set(CMAKE_XCODE_ATTRIBUTE_CODE_SIGNING_REQUIRED "NO") +set(CMAKE_SHARED_LIBRARY_PREFIX "lib") +set(CMAKE_SHARED_LIBRARY_SUFFIX ".dylib") +set(CMAKE_SHARED_MODULE_PREFIX "lib") +set(CMAKE_SHARED_MODULE_SUFFIX ".so") +set(CMAKE_C_COMPILER_ABI ELF) +set(CMAKE_CXX_COMPILER_ABI ELF) +set(CMAKE_C_HAS_ISYSROOT 1) +set(CMAKE_CXX_HAS_ISYSROOT 1) +set(CMAKE_MODULE_EXISTS 1) +set(CMAKE_DL_LIBS "") +set(CMAKE_C_OSX_COMPATIBILITY_VERSION_FLAG "-compatibility_version ") +set(CMAKE_C_OSX_CURRENT_VERSION_FLAG "-current_version ") +set(CMAKE_CXX_OSX_COMPATIBILITY_VERSION_FLAG "${CMAKE_C_OSX_COMPATIBILITY_VERSION_FLAG}") +set(CMAKE_CXX_OSX_CURRENT_VERSION_FLAG "${CMAKE_C_OSX_CURRENT_VERSION_FLAG}") + +if(ARCHS MATCHES "((^|;|, )(arm64|arm64e|x86_64))+") + set(CMAKE_C_SIZEOF_DATA_PTR 8) + set(CMAKE_CXX_SIZEOF_DATA_PTR 8) + if(ARCHS MATCHES "((^|;|, )(arm64|arm64e))+") + set(CMAKE_SYSTEM_PROCESSOR "aarch64") + else() + set(CMAKE_SYSTEM_PROCESSOR "x86_64") + endif() +else() + set(CMAKE_C_SIZEOF_DATA_PTR 4) + set(CMAKE_CXX_SIZEOF_DATA_PTR 4) + set(CMAKE_SYSTEM_PROCESSOR "arm") +endif() + +# Note that only Xcode 7+ supports the newer more specific: +# -m${SDK_NAME}-version-min flags, older versions of Xcode use: +# -m(ios/ios-simulator)-version-min instead. +if(${CMAKE_VERSION} VERSION_LESS "3.11") + if(PLATFORM_INT STREQUAL "OS" OR PLATFORM_INT STREQUAL "OS64") + if(XCODE_VERSION_INT VERSION_LESS 7.0) + set(SDK_NAME_VERSION_FLAGS + "-mios-version-min=${DEPLOYMENT_TARGET}") + else() + # Xcode 7.0+ uses flags we can build directly from SDK_NAME. + set(SDK_NAME_VERSION_FLAGS + "-m${SDK_NAME}-version-min=${DEPLOYMENT_TARGET}") + endif() + elseif(PLATFORM_INT STREQUAL "TVOS") + set(SDK_NAME_VERSION_FLAGS + "-mtvos-version-min=${DEPLOYMENT_TARGET}") + elseif(PLATFORM_INT STREQUAL "SIMULATOR_TVOS") + set(SDK_NAME_VERSION_FLAGS + "-mtvos-simulator-version-min=${DEPLOYMENT_TARGET}") + elseif(PLATFORM_INT STREQUAL "WATCHOS") + set(SDK_NAME_VERSION_FLAGS + "-mwatchos-version-min=${DEPLOYMENT_TARGET}") + elseif(PLATFORM_INT STREQUAL "SIMULATOR_WATCHOS") + set(SDK_NAME_VERSION_FLAGS + "-mwatchos-simulator-version-min=${DEPLOYMENT_TARGET}") + elseif(PLATFORM_INT STREQUAL "MAC") + set(SDK_NAME_VERSION_FLAGS + "-mmacosx-version-min=${DEPLOYMENT_TARGET}") + else() + # SIMULATOR or SIMULATOR64 both use -mios-simulator-version-min. + set(SDK_NAME_VERSION_FLAGS + "-mios-simulator-version-min=${DEPLOYMENT_TARGET}") + endif() +elseif(NOT PLATFORM_INT MATCHES "^MAC_CATALYST") + # Newer versions of CMake sets the version min flags correctly, skip this for Mac Catalyst targets + set(CMAKE_OSX_DEPLOYMENT_TARGET ${DEPLOYMENT_TARGET}) +endif() + +if(DEFINED APPLE_TARGET_TRIPLE_INT) + set(APPLE_TARGET_TRIPLE ${APPLE_TARGET_TRIPLE_INT} CACHE INTERNAL "") + set(CMAKE_C_COMPILER_TARGET ${APPLE_TARGET_TRIPLE}) + set(CMAKE_CXX_COMPILER_TARGET ${APPLE_TARGET_TRIPLE}) + set(CMAKE_ASM_COMPILER_TARGET ${APPLE_TARGET_TRIPLE}) +endif() + +if(PLATFORM_INT MATCHES "^MAC_CATALYST") + set(C_TARGET_FLAGS "-isystem ${CMAKE_OSX_SYSROOT_INT}/System/iOSSupport/usr/include -iframework ${CMAKE_OSX_SYSROOT_INT}/System/iOSSupport/System/Library/Frameworks") +endif() + +if(ENABLE_BITCODE_INT) + set(BITCODE "-fembed-bitcode") + set(CMAKE_XCODE_ATTRIBUTE_BITCODE_GENERATION_MODE "bitcode") + set(CMAKE_XCODE_ATTRIBUTE_ENABLE_BITCODE "YES") +else() + set(BITCODE "") + set(CMAKE_XCODE_ATTRIBUTE_ENABLE_BITCODE "NO") +endif() + +if(ENABLE_ARC_INT) + set(FOBJC_ARC "-fobjc-arc") + set(CMAKE_XCODE_ATTRIBUTE_CLANG_ENABLE_OBJC_ARC "YES") +else() + set(FOBJC_ARC "-fno-objc-arc") + set(CMAKE_XCODE_ATTRIBUTE_CLANG_ENABLE_OBJC_ARC "NO") +endif() + +if(NAMED_LANGUAGE_SUPPORT_INT) + set(OBJC_VARS "-fobjc-abi-version=2 -DOBJC_OLD_DISPATCH_PROTOTYPES=0") + set(OBJC_LEGACY_VARS "") +else() + set(OBJC_VARS "") + set(OBJC_LEGACY_VARS "-fobjc-abi-version=2 -DOBJC_OLD_DISPATCH_PROTOTYPES=0") +endif() + +if(NOT ENABLE_VISIBILITY_INT) + foreach(lang ${languages}) + set(CMAKE_${lang}_VISIBILITY_PRESET "hidden" CACHE INTERNAL "") + endforeach() + set(CMAKE_XCODE_ATTRIBUTE_GCC_SYMBOLS_PRIVATE_EXTERN "YES") + set(VISIBILITY "-fvisibility=hidden -fvisibility-inlines-hidden") +else() + foreach(lang ${languages}) + set(CMAKE_${lang}_VISIBILITY_PRESET "default" CACHE INTERNAL "") + endforeach() + set(CMAKE_XCODE_ATTRIBUTE_GCC_SYMBOLS_PRIVATE_EXTERN "NO") + set(VISIBILITY "-fvisibility=default") +endif() + +if(DEFINED APPLE_TARGET_TRIPLE) + set(APPLE_TARGET_TRIPLE_FLAG "-target ${APPLE_TARGET_TRIPLE}") +endif() + +#Check if Xcode generator is used, since that will handle these flags automagically +if(CMAKE_GENERATOR MATCHES "Xcode") + message(STATUS "Not setting any manual command-line buildflags, since Xcode is selected as generator. Modifying the Xcode build-settings directly instead.") +else() + set(CMAKE_C_FLAGS "${C_TARGET_FLAGS} ${APPLE_TARGET_TRIPLE_FLAG} ${SDK_NAME_VERSION_FLAGS} ${OBJC_LEGACY_VARS} ${BITCODE} ${VISIBILITY} ${CMAKE_C_FLAGS}") + set(CMAKE_C_FLAGS_DEBUG "-O0 -g ${CMAKE_C_FLAGS_DEBUG}") + set(CMAKE_C_FLAGS_MINSIZEREL "-DNDEBUG -Os ${CMAKE_C_FLAGS_MINSIZEREL}") + set(CMAKE_C_FLAGS_RELWITHDEBINFO "-DNDEBUG -O2 -g ${CMAKE_C_FLAGS_RELWITHDEBINFO}") + set(CMAKE_C_FLAGS_RELEASE "-DNDEBUG -O3 ${CMAKE_C_FLAGS_RELEASE}") + set(CMAKE_CXX_FLAGS "${C_TARGET_FLAGS} ${APPLE_TARGET_TRIPLE_FLAG} ${SDK_NAME_VERSION_FLAGS} ${OBJC_LEGACY_VARS} ${BITCODE} ${VISIBILITY} ${CMAKE_CXX_FLAGS}") + set(CMAKE_CXX_FLAGS_DEBUG "-O0 -g ${CMAKE_CXX_FLAGS_DEBUG}") + set(CMAKE_CXX_FLAGS_MINSIZEREL "-DNDEBUG -Os ${CMAKE_CXX_FLAGS_MINSIZEREL}") + set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-DNDEBUG -O2 -g ${CMAKE_CXX_FLAGS_RELWITHDEBINFO}") + set(CMAKE_CXX_FLAGS_RELEASE "-DNDEBUG -O3 ${CMAKE_CXX_FLAGS_RELEASE}") + if(NAMED_LANGUAGE_SUPPORT_INT) + set(CMAKE_OBJC_FLAGS "${C_TARGET_FLAGS} ${APPLE_TARGET_TRIPLE_FLAG} ${SDK_NAME_VERSION_FLAGS} ${BITCODE} ${VISIBILITY} ${FOBJC_ARC} ${OBJC_VARS} ${CMAKE_OBJC_FLAGS}") + set(CMAKE_OBJC_FLAGS_DEBUG "-O0 -g ${CMAKE_OBJC_FLAGS_DEBUG}") + set(CMAKE_OBJC_FLAGS_MINSIZEREL "-DNDEBUG -Os ${CMAKE_OBJC_FLAGS_MINSIZEREL}") + set(CMAKE_OBJC_FLAGS_RELWITHDEBINFO "-DNDEBUG -O2 -g ${CMAKE_OBJC_FLAGS_RELWITHDEBINFO}") + set(CMAKE_OBJC_FLAGS_RELEASE "-DNDEBUG -O3 ${CMAKE_OBJC_FLAGS_RELEASE}") + set(CMAKE_OBJCXX_FLAGS "${C_TARGET_FLAGS} ${APPLE_TARGET_TRIPLE_FLAG} ${SDK_NAME_VERSION_FLAGS} ${BITCODE} ${VISIBILITY} ${FOBJC_ARC} ${OBJC_VARS} ${CMAKE_OBJCXX_FLAGS}") + set(CMAKE_OBJCXX_FLAGS_DEBUG "-O0 -g ${CMAKE_OBJCXX_FLAGS_DEBUG}") + set(CMAKE_OBJCXX_FLAGS_MINSIZEREL "-DNDEBUG -Os ${CMAKE_OBJCXX_FLAGS_MINSIZEREL}") + set(CMAKE_OBJCXX_FLAGS_RELWITHDEBINFO "-DNDEBUG -O2 -g ${CMAKE_OBJCXX_FLAGS_RELWITHDEBINFO}") + set(CMAKE_OBJCXX_FLAGS_RELEASE "-DNDEBUG -O3 ${CMAKE_OBJCXX_FLAGS_RELEASE}") + endif() + set(CMAKE_C_LINK_FLAGS "${C_TARGET_FLAGS} ${SDK_NAME_VERSION_FLAGS} -Wl,-search_paths_first ${CMAKE_C_LINK_FLAGS}") + set(CMAKE_CXX_LINK_FLAGS "${C_TARGET_FLAGS} ${SDK_NAME_VERSION_FLAGS} -Wl,-search_paths_first ${CMAKE_CXX_LINK_FLAGS}") + if(NAMED_LANGUAGE_SUPPORT_INT) + set(CMAKE_OBJC_LINK_FLAGS "${C_TARGET_FLAGS} ${SDK_NAME_VERSION_FLAGS} -Wl,-search_paths_first ${CMAKE_OBJC_LINK_FLAGS}") + set(CMAKE_OBJCXX_LINK_FLAGS "${C_TARGET_FLAGS} ${SDK_NAME_VERSION_FLAGS} -Wl,-search_paths_first ${CMAKE_OBJCXX_LINK_FLAGS}") + endif() + set(CMAKE_ASM_FLAGS "${CMAKE_C_FLAGS} -x assembler-with-cpp -arch ${CMAKE_OSX_ARCHITECTURES} ${APPLE_TARGET_TRIPLE_FLAG}") +endif() + +## Print status messages to inform of the current state +message(STATUS "Configuring ${SDK_NAME} build for platform: ${PLATFORM_INT}, architecture(s): ${ARCHS}") +message(STATUS "Using SDK: ${CMAKE_OSX_SYSROOT_INT}") +message(STATUS "Using C compiler: ${CMAKE_C_COMPILER}") +message(STATUS "Using CXX compiler: ${CMAKE_CXX_COMPILER}") +message(STATUS "Using libtool: ${BUILD_LIBTOOL}") +message(STATUS "Using install name tool: ${CMAKE_INSTALL_NAME_TOOL}") +if(DEFINED APPLE_TARGET_TRIPLE) + message(STATUS "Autoconf target triple: ${APPLE_TARGET_TRIPLE}") +endif() +message(STATUS "Using minimum deployment version: ${DEPLOYMENT_TARGET}" + " (SDK version: ${SDK_VERSION})") +if(MODERN_CMAKE) + message(STATUS "Merging integrated CMake 3.14+ iOS,tvOS,watchOS,macOS toolchain(s) with this toolchain!") + if(PLATFORM_INT MATCHES ".*COMBINED") + message(STATUS "Will combine built (static) artifacts into FAT lib...") + endif() +endif() +if(CMAKE_GENERATOR MATCHES "Xcode") + message(STATUS "Using Xcode version: ${XCODE_VERSION_INT}") +endif() +message(STATUS "CMake version: ${CMAKE_VERSION}") +if(DEFINED SDK_NAME_VERSION_FLAGS) + message(STATUS "Using version flags: ${SDK_NAME_VERSION_FLAGS}") +endif() +message(STATUS "Using a data_ptr size of: ${CMAKE_CXX_SIZEOF_DATA_PTR}") +if(ENABLE_BITCODE_INT) + message(STATUS "Bitcode: Enabled") +else() + message(STATUS "Bitcode: Disabled") +endif() + +if(ENABLE_ARC_INT) + message(STATUS "ARC: Enabled") +else() + message(STATUS "ARC: Disabled") +endif() + +if(ENABLE_VISIBILITY_INT) + message(STATUS "Hiding symbols: Disabled") +else() + message(STATUS "Hiding symbols: Enabled") +endif() + +# Set global properties +set_property(GLOBAL PROPERTY PLATFORM "${PLATFORM}") +set_property(GLOBAL PROPERTY APPLE_TARGET_TRIPLE "${APPLE_TARGET_TRIPLE_INT}") +set_property(GLOBAL PROPERTY SDK_VERSION "${SDK_VERSION}") +set_property(GLOBAL PROPERTY XCODE_VERSION "${XCODE_VERSION_INT}") +set_property(GLOBAL PROPERTY OSX_ARCHITECTURES "${CMAKE_OSX_ARCHITECTURES}") + +# Export configurable variables for the try_compile() command. +set(CMAKE_TRY_COMPILE_PLATFORM_VARIABLES + PLATFORM + XCODE_VERSION_INT + SDK_VERSION + NAMED_LANGUAGE_SUPPORT + DEPLOYMENT_TARGET + CMAKE_DEVELOPER_ROOT + CMAKE_OSX_SYSROOT_INT + ENABLE_BITCODE + ENABLE_ARC + CMAKE_ASM_COMPILER + CMAKE_C_COMPILER + CMAKE_C_COMPILER_TARGET + CMAKE_CXX_COMPILER + CMAKE_CXX_COMPILER_TARGET + BUILD_LIBTOOL + CMAKE_INSTALL_NAME_TOOL + CMAKE_C_FLAGS + CMAKE_C_DEBUG + CMAKE_C_MINSIZEREL + CMAKE_C_RELWITHDEBINFO + CMAKE_C_RELEASE + CMAKE_CXX_FLAGS + CMAKE_CXX_FLAGS_DEBUG + CMAKE_CXX_FLAGS_MINSIZEREL + CMAKE_CXX_FLAGS_RELWITHDEBINFO + CMAKE_CXX_FLAGS_RELEASE + CMAKE_C_LINK_FLAGS + CMAKE_CXX_LINK_FLAGS + CMAKE_ASM_FLAGS +) + +if(NAMED_LANGUAGE_SUPPORT_INT) + list(APPEND CMAKE_TRY_COMPILE_PLATFORM_VARIABLES + CMAKE_OBJC_FLAGS + CMAKE_OBJC_DEBUG + CMAKE_OBJC_MINSIZEREL + CMAKE_OBJC_RELWITHDEBINFO + CMAKE_OBJC_RELEASE + CMAKE_OBJCXX_FLAGS + CMAKE_OBJCXX_DEBUG + CMAKE_OBJCXX_MINSIZEREL + CMAKE_OBJCXX_RELWITHDEBINFO + CMAKE_OBJCXX_RELEASE + CMAKE_OBJC_LINK_FLAGS + CMAKE_OBJCXX_LINK_FLAGS + ) +endif() + +set(CMAKE_PLATFORM_HAS_INSTALLNAME 1) +set(CMAKE_SHARED_LINKER_FLAGS "-rpath @executable_path/Frameworks -rpath @loader_path/Frameworks") +set(CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS "-dynamiclib -Wl,-headerpad_max_install_names") +set(CMAKE_SHARED_MODULE_CREATE_C_FLAGS "-bundle -Wl,-headerpad_max_install_names") +set(CMAKE_SHARED_MODULE_LOADER_C_FLAG "-Wl,-bundle_loader,") +set(CMAKE_SHARED_MODULE_LOADER_CXX_FLAG "-Wl,-bundle_loader,") +set(CMAKE_FIND_LIBRARY_SUFFIXES ".tbd" ".dylib" ".so" ".a") +set(CMAKE_SHARED_LIBRARY_SONAME_C_FLAG "-install_name") + +# Set the find root to the SDK developer roots. +# Note: CMAKE_FIND_ROOT_PATH is only useful when cross-compiling. Thus, do not set on macOS builds. +if(NOT PLATFORM_INT MATCHES "^MAC.*$") + list(APPEND CMAKE_FIND_ROOT_PATH "${CMAKE_OSX_SYSROOT_INT}" CACHE INTERNAL "") + set(CMAKE_IGNORE_PATH "/System/Library/Frameworks;/usr/local/lib" CACHE INTERNAL "") +endif() + +# Default to searching for frameworks first. +set(CMAKE_FIND_FRAMEWORK FIRST) + +# Set up the default search directories for frameworks. +if(PLATFORM_INT MATCHES "^MAC_CATALYST") + set(CMAKE_FRAMEWORK_PATH + ${CMAKE_DEVELOPER_ROOT}/Library/PrivateFrameworks + ${CMAKE_OSX_SYSROOT_INT}/System/Library/Frameworks + ${CMAKE_OSX_SYSROOT_INT}/System/iOSSupport/System/Library/Frameworks + ${CMAKE_FRAMEWORK_PATH} CACHE INTERNAL "") +else() + set(CMAKE_FRAMEWORK_PATH + ${CMAKE_DEVELOPER_ROOT}/Library/PrivateFrameworks + ${CMAKE_OSX_SYSROOT_INT}/System/Library/Frameworks + ${CMAKE_FRAMEWORK_PATH} CACHE INTERNAL "") +endif() + +# By default, search both the specified iOS SDK and the remainder of the host filesystem. +if(NOT CMAKE_FIND_ROOT_PATH_MODE_PROGRAM) + set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM BOTH CACHE INTERNAL "") +endif() +if(NOT CMAKE_FIND_ROOT_PATH_MODE_LIBRARY) + set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY BOTH CACHE INTERNAL "") +endif() +if(NOT CMAKE_FIND_ROOT_PATH_MODE_INCLUDE) + set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE BOTH CACHE INTERNAL "") +endif() +if(NOT CMAKE_FIND_ROOT_PATH_MODE_PACKAGE) + set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE BOTH CACHE INTERNAL "") +endif() + +# +# Some helper-macros below to simplify and beautify the CMakeFile +# + +# This little macro lets you set any Xcode specific property. +macro(set_xcode_property TARGET XCODE_PROPERTY XCODE_VALUE XCODE_RELVERSION) + set(XCODE_RELVERSION_I "${XCODE_RELVERSION}") + if(XCODE_RELVERSION_I STREQUAL "All") + set_property(TARGET ${TARGET} PROPERTY XCODE_ATTRIBUTE_${XCODE_PROPERTY} "${XCODE_VALUE}") + else() + set_property(TARGET ${TARGET} PROPERTY XCODE_ATTRIBUTE_${XCODE_PROPERTY}[variant=${XCODE_RELVERSION_I}] "${XCODE_VALUE}") + endif() +endmacro(set_xcode_property) + +# This macro lets you find executable programs on the host system. +macro(find_host_package) + set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) + set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY NEVER) + set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE NEVER) + set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE NEVER) + set(_TOOLCHAIN_IOS ${IOS}) + set(IOS OFF) + find_package(${ARGN}) + set(IOS ${_TOOLCHAIN_IOS}) + set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM BOTH) + set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY BOTH) + set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE BOTH) + set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE BOTH) +endmacro(find_host_package) diff --git a/runtime/ios/CMakeLists.txt b/runtime/ios/CMakeLists.txt new file mode 100644 index 0000000000..9fd328997a --- /dev/null +++ b/runtime/ios/CMakeLists.txt @@ -0,0 +1,75 @@ +cmake_minimum_required(VERSION 3.14 FATAL_ERROR) + +project(wenet VERSION 0.1) + +option(CXX11_ABI "whether to use CXX11_ABI libtorch" OFF) +option(GRAPH_TOOLS "whether to build TLG graph tools" OFF) +option(BUILD_TESTING "whether to build unit test" ON) + +option(GRPC "whether to build with gRPC" OFF) +# TODO(Binbin Zhang): Change websocket to OFF since it depends on boost +# which is a very big library +option(WEBSOCKET "whether to build with websocket" ON) +option(TORCH "whether to build with Torch" ON) +option(ONNX "whether to build with ONNX" OFF) +option(GPU "whether to build with GPU" OFF) + +set(CMAKE_VERBOSE_MAKEFILE OFF) + +include(FetchContent) +set(FETCHCONTENT_QUIET OFF) +get_filename_component(fc_base "fc_base" REALPATH BASE_DIR "${CMAKE_CURRENT_SOURCE_DIR}") +set(FETCHCONTENT_BASE_DIR ${fc_base}) + +list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake) + +if(NOT MSVC) + # Keep the same with openfst, -fPIC or -fpic + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14 -pthread -fPIC") +else() + set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON) + add_compile_options("$<$:/utf-8>") +endif() + +# Include all dependency +if(TORCH) + include(libtorch) +endif() +if(ONNX) + include(onnx) +endif() +include(openfst) +include_directories( + ${CMAKE_CURRENT_SOURCE_DIR} + ${CMAKE_CURRENT_SOURCE_DIR}/kaldi + ${CMAKE_CURRENT_SOURCE_DIR}/build/Pods/LibTorch/install/include +) + +# Build all libraries +add_subdirectory(utils) +add_subdirectory(frontend) +add_subdirectory(post_processor) +add_subdirectory(kaldi) # kaldi: wfst based decoder +add_subdirectory(decoder) +add_subdirectory(api) + +# Optionally, you can build with websocket +if(WEBSOCKET) + include(boost) + add_subdirectory(websocket) +endif() + +# Optionally, you can build with gRPC +if(GRPC) + include(grpc) + add_subdirectory(grpc) +endif() + +# Build all bins +add_subdirectory(bin) + +# Unit Test +if(BUILD_TESTING) + include(gtest) + add_subdirectory(test) +endif() diff --git a/runtime/ios/README.md b/runtime/ios/README.md new file mode 100644 index 0000000000..4fca5c1ffc --- /dev/null +++ b/runtime/ios/README.md @@ -0,0 +1,42 @@ +# WeNet On-device ASR iOS Demo + +## Build application from source code + +### 1) Generate cmake project and install LibTorch pod + +``` +cd runtime/ios/build +cmake .. -G Xcode -DTORCH=OFF -DONNX=OFF -DIOS=ON -DGRAPH_TOOLS=ON -DBUILD_TESTING=OFF -DCMAKE_TOOLCHAIN_FILE=../toolchains/ios.toolchain.cmake -DPLATFORM=OS64 -DENABLE_BITCODE=FALSE +pod install +``` + +### 2) Remove executable targets in wenet project + +Open wenet.xcworkspace in runtime/ios/build folder with Xcode, remove all 47 executable targets in wenet project and Pods-decoder_main target in Pods project, leave static library targets only, close Xcode to save workspace. + +### 3) Build static libraries + +``` +# Build debug version +cmake --build . --config Debug + +# Build release version +cmake --build . --config Release +``` + +### 4) Build and run iOS application + +You can use our pretrained model (click the following link to download): + +[AISHELL-1](https://wenet-1256283475.cos.ap-shanghai.myqcloud.com/models/aishell/20210601_u2%2B%2B_conformer_libtorch.tar.gz) +| [AISHELL-2](https://wenet-1256283475.cos.ap-shanghai.myqcloud.com/models/aishell2/20210618_u2pp_conformer_libtorch.tar.gz) +| [GigaSpeech](https://wenet-1256283475.cos.ap-shanghai.myqcloud.com/models/gigaspeech/20210728_u2pp_conformer_libtorch.tar.gz) +| [LibriSpeech](https://wenet-1256283475.cos.ap-shanghai.myqcloud.com/models/librispeech/20210610_u2pp_conformer_libtorch.tar.gz) +| [Multi-CN](https://wenet-1256283475.cos.ap-shanghai.myqcloud.com/models/multi_cn/20210815_unified_conformer_libtorch.tar.gz) + + +Or you can train your own model using WeNet training pipeline on your data. + +When your model is ready, put `final.zip` and `units.txt` into model (`WenetDemo/WenetDemo/model`) folder. + +Open WenetDemo.xcodeproj with Xcode, build and run on iOS device. diff --git a/runtime/ios/WenetDemo/WenetDemo.xcodeproj/project.pbxproj b/runtime/ios/WenetDemo/WenetDemo.xcodeproj/project.pbxproj new file mode 100644 index 0000000000..e567a04468 --- /dev/null +++ b/runtime/ios/WenetDemo/WenetDemo.xcodeproj/project.pbxproj @@ -0,0 +1,563 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 56; + objects = { + +/* Begin PBXBuildFile section */ + 374FEB34291019EE00513F88 /* libeigen_blas.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 37FD7E1E2910198A00853C23 /* libeigen_blas.a */; }; + 37C64C892912A94B00BFCE0B /* final.zip in Resources */ = {isa = PBXBuildFile; fileRef = 37C64C882912A94A00BFCE0B /* final.zip */; }; + 37C64C8B2912ABE900BFCE0B /* units.txt in Resources */ = {isa = PBXBuildFile; fileRef = 37C64C8A2912ABE900BFCE0B /* units.txt */; }; + 37C64C8F2912ADDD00BFCE0B /* libfst.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 37C64C8E2912ADDD00BFCE0B /* libfst.a */; }; + 37C64C942912AF7F00BFCE0B /* libkaldi-decoder.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 37C64C8C2912AD3300BFCE0B /* libkaldi-decoder.a */; }; + 37C64C962912AFC900BFCE0B /* libpost_processor.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 37C64C952912AFC900BFCE0B /* libpost_processor.a */; }; + 37C64C982912B06800BFCE0B /* libutils.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 37C64C972912B06800BFCE0B /* libutils.a */; }; + 37C64C9A2912B0A000BFCE0B /* libfrontend.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 37C64C992912B0A000BFCE0B /* libfrontend.a */; }; + 37FD7E032910094300853C23 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 37FD7E022910094300853C23 /* AppDelegate.swift */; }; + 37FD7E052910094300853C23 /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 37FD7E042910094300853C23 /* SceneDelegate.swift */; }; + 37FD7E072910094300853C23 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 37FD7E062910094300853C23 /* ViewController.swift */; }; + 37FD7E0A2910094300853C23 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 37FD7E082910094300853C23 /* Main.storyboard */; }; + 37FD7E0C2910094500853C23 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 37FD7E0B2910094500853C23 /* Assets.xcassets */; }; + 37FD7E0F2910094500853C23 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 37FD7E0D2910094500853C23 /* LaunchScreen.storyboard */; }; + 37FD7E1A291009EC00853C23 /* wenet.mm in Sources */ = {isa = PBXBuildFile; fileRef = 37FD7E18291009EC00853C23 /* wenet.mm */; }; + 37FD7E1D2910195900853C23 /* libdecoder.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 37FD7E1C2910195900853C23 /* libdecoder.a */; }; + 37FD7E282910198B00853C23 /* libpthreadpool.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 37FD7E1F2910198B00853C23 /* libpthreadpool.a */; }; + 37FD7E292910198B00853C23 /* libc10.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 37FD7E202910198B00853C23 /* libc10.a */; }; + 37FD7E2A2910198B00853C23 /* libtorch_cpu.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 37FD7E212910198B00853C23 /* libtorch_cpu.a */; }; + 37FD7E2B2910198B00853C23 /* libtorch.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 37FD7E222910198B00853C23 /* libtorch.a */; }; + 37FD7E2C2910198B00853C23 /* libclog.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 37FD7E232910198B00853C23 /* libclog.a */; }; + 37FD7E2D2910198B00853C23 /* libcpuinfo.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 37FD7E242910198B00853C23 /* libcpuinfo.a */; }; + 37FD7E2E2910198C00853C23 /* libXNNPACK.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 37FD7E252910198B00853C23 /* libXNNPACK.a */; }; + 37FD7E2F2910198C00853C23 /* libpytorch_qnnpack.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 37FD7E262910198B00853C23 /* libpytorch_qnnpack.a */; }; +/* End PBXBuildFile section */ + +/* Begin PBXFileReference section */ + 373FDD93291BE53D00DF4BEA /* libglog.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libglog.a; path = "../fc_base/glog-build/Release-iphoneos/libglog.a"; sourceTree = ""; }; + 373FDD95291BE5A800DF4BEA /* libgflags_nothreads.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libgflags_nothreads.a; path = "../fc_base/gflags-build/Release-iphoneos/libgflags_nothreads.a"; sourceTree = ""; }; + 37C64C882912A94A00BFCE0B /* final.zip */ = {isa = PBXFileReference; lastKnownFileType = archive.zip; path = final.zip; sourceTree = ""; }; + 37C64C8A2912ABE900BFCE0B /* units.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = units.txt; sourceTree = ""; }; + 37C64C8C2912AD3300BFCE0B /* libkaldi-decoder.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = "libkaldi-decoder.a"; path = "../build/kaldi/Debug-iphoneos/libkaldi-decoder.a"; sourceTree = ""; }; + 37C64C8E2912ADDD00BFCE0B /* libfst.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libfst.a; path = "../fc_base/openfst-build/src/lib/Debug-iphoneos/libfst.a"; sourceTree = ""; }; + 37C64C902912AE2B00BFCE0B /* libgflags_nothreads_debug.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libgflags_nothreads_debug.a; path = "../fc_base/gflags-build/Debug-iphoneos/libgflags_nothreads_debug.a"; sourceTree = ""; }; + 37C64C922912AE7E00BFCE0B /* libglogd.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libglogd.a; path = "../fc_base/glog-build/Debug-iphoneos/libglogd.a"; sourceTree = ""; }; + 37C64C952912AFC900BFCE0B /* libpost_processor.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libpost_processor.a; path = "../build/post_processor/Debug-iphoneos/libpost_processor.a"; sourceTree = ""; }; + 37C64C972912B06800BFCE0B /* libutils.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libutils.a; path = "../build/utils/Debug-iphoneos/libutils.a"; sourceTree = ""; }; + 37C64C992912B0A000BFCE0B /* libfrontend.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libfrontend.a; path = "../build/frontend/Debug-iphoneos/libfrontend.a"; sourceTree = ""; }; + 37FD7DFF2910094300853C23 /* WenetDemo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = WenetDemo.app; sourceTree = BUILT_PRODUCTS_DIR; }; + 37FD7E022910094300853C23 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; + 37FD7E042910094300853C23 /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = ""; }; + 37FD7E062910094300853C23 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; + 37FD7E092910094300853C23 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; + 37FD7E0B2910094500853C23 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; + 37FD7E0E2910094500853C23 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; + 37FD7E102910094500853C23 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + 37FD7E17291009EC00853C23 /* WenetDemo-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "WenetDemo-Bridging-Header.h"; sourceTree = ""; }; + 37FD7E18291009EC00853C23 /* wenet.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = wenet.mm; sourceTree = ""; }; + 37FD7E19291009EC00853C23 /* wenet.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = wenet.h; sourceTree = ""; }; + 37FD7E1C2910195900853C23 /* libdecoder.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libdecoder.a; path = "../wenet/runtime/ios/build/decoder/Debug-iphoneos/libdecoder.a"; sourceTree = ""; }; + 37FD7E1E2910198A00853C23 /* libeigen_blas.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libeigen_blas.a; path = ../wenet/runtime/ios/build/Pods/LibTorch/install/lib/libeigen_blas.a; sourceTree = ""; }; + 37FD7E1F2910198B00853C23 /* libpthreadpool.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libpthreadpool.a; path = ../wenet/runtime/ios/build/Pods/LibTorch/install/lib/libpthreadpool.a; sourceTree = ""; }; + 37FD7E202910198B00853C23 /* libc10.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libc10.a; path = ../wenet/runtime/ios/build/Pods/LibTorch/install/lib/libc10.a; sourceTree = ""; }; + 37FD7E212910198B00853C23 /* libtorch_cpu.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libtorch_cpu.a; path = ../wenet/runtime/ios/build/Pods/LibTorch/install/lib/libtorch_cpu.a; sourceTree = ""; }; + 37FD7E222910198B00853C23 /* libtorch.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libtorch.a; path = ../wenet/runtime/ios/build/Pods/LibTorch/install/lib/libtorch.a; sourceTree = ""; }; + 37FD7E232910198B00853C23 /* libclog.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libclog.a; path = ../wenet/runtime/ios/build/Pods/LibTorch/install/lib/libclog.a; sourceTree = ""; }; + 37FD7E242910198B00853C23 /* libcpuinfo.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libcpuinfo.a; path = ../wenet/runtime/ios/build/Pods/LibTorch/install/lib/libcpuinfo.a; sourceTree = ""; }; + 37FD7E252910198B00853C23 /* libXNNPACK.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libXNNPACK.a; path = ../wenet/runtime/ios/build/Pods/LibTorch/install/lib/libXNNPACK.a; sourceTree = ""; }; + 37FD7E262910198B00853C23 /* libpytorch_qnnpack.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libpytorch_qnnpack.a; path = ../wenet/runtime/ios/build/Pods/LibTorch/install/lib/libpytorch_qnnpack.a; sourceTree = ""; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + 37FD7DFC2910094300853C23 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + 37C64C9A2912B0A000BFCE0B /* libfrontend.a in Frameworks */, + 37C64C982912B06800BFCE0B /* libutils.a in Frameworks */, + 37C64C962912AFC900BFCE0B /* libpost_processor.a in Frameworks */, + 37C64C942912AF7F00BFCE0B /* libkaldi-decoder.a in Frameworks */, + 37C64C8F2912ADDD00BFCE0B /* libfst.a in Frameworks */, + 374FEB34291019EE00513F88 /* libeigen_blas.a in Frameworks */, + 37FD7E282910198B00853C23 /* libpthreadpool.a in Frameworks */, + 37FD7E292910198B00853C23 /* libc10.a in Frameworks */, + 37FD7E2A2910198B00853C23 /* libtorch_cpu.a in Frameworks */, + 37FD7E2B2910198B00853C23 /* libtorch.a in Frameworks */, + 37FD7E2C2910198B00853C23 /* libclog.a in Frameworks */, + 37FD7E2D2910198B00853C23 /* libcpuinfo.a in Frameworks */, + 37FD7E2E2910198C00853C23 /* libXNNPACK.a in Frameworks */, + 37FD7E2F2910198C00853C23 /* libpytorch_qnnpack.a in Frameworks */, + 37FD7E1D2910195900853C23 /* libdecoder.a in Frameworks */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + 37C64C812912A21300BFCE0B /* model */ = { + isa = PBXGroup; + children = ( + 37C64C8A2912ABE900BFCE0B /* units.txt */, + 37C64C882912A94A00BFCE0B /* final.zip */, + ); + path = model; + sourceTree = ""; + }; + 37FD7DF62910094300853C23 = { + isa = PBXGroup; + children = ( + 37FD7E012910094300853C23 /* WenetDemo */, + 37FD7E002910094300853C23 /* Products */, + 37FD7E1B2910195900853C23 /* Frameworks */, + ); + sourceTree = ""; + }; + 37FD7E002910094300853C23 /* Products */ = { + isa = PBXGroup; + children = ( + 37FD7DFF2910094300853C23 /* WenetDemo.app */, + ); + name = Products; + sourceTree = ""; + }; + 37FD7E012910094300853C23 /* WenetDemo */ = { + isa = PBXGroup; + children = ( + 37C64C812912A21300BFCE0B /* model */, + 37FD7E16291009B900853C23 /* wenet */, + 37FD7E022910094300853C23 /* AppDelegate.swift */, + 37FD7E042910094300853C23 /* SceneDelegate.swift */, + 37FD7E062910094300853C23 /* ViewController.swift */, + 37FD7E082910094300853C23 /* Main.storyboard */, + 37FD7E0B2910094500853C23 /* Assets.xcassets */, + 37FD7E0D2910094500853C23 /* LaunchScreen.storyboard */, + 37FD7E102910094500853C23 /* Info.plist */, + ); + path = WenetDemo; + sourceTree = ""; + }; + 37FD7E16291009B900853C23 /* wenet */ = { + isa = PBXGroup; + children = ( + 37FD7E18291009EC00853C23 /* wenet.mm */, + 37FD7E19291009EC00853C23 /* wenet.h */, + 37FD7E17291009EC00853C23 /* WenetDemo-Bridging-Header.h */, + ); + path = wenet; + sourceTree = ""; + }; + 37FD7E1B2910195900853C23 /* Frameworks */ = { + isa = PBXGroup; + children = ( + 373FDD95291BE5A800DF4BEA /* libgflags_nothreads.a */, + 373FDD93291BE53D00DF4BEA /* libglog.a */, + 37C64C992912B0A000BFCE0B /* libfrontend.a */, + 37C64C972912B06800BFCE0B /* libutils.a */, + 37C64C952912AFC900BFCE0B /* libpost_processor.a */, + 37C64C922912AE7E00BFCE0B /* libglogd.a */, + 37C64C902912AE2B00BFCE0B /* libgflags_nothreads_debug.a */, + 37C64C8E2912ADDD00BFCE0B /* libfst.a */, + 37C64C8C2912AD3300BFCE0B /* libkaldi-decoder.a */, + 37FD7E202910198B00853C23 /* libc10.a */, + 37FD7E232910198B00853C23 /* libclog.a */, + 37FD7E242910198B00853C23 /* libcpuinfo.a */, + 37FD7E1E2910198A00853C23 /* libeigen_blas.a */, + 37FD7E1F2910198B00853C23 /* libpthreadpool.a */, + 37FD7E262910198B00853C23 /* libpytorch_qnnpack.a */, + 37FD7E212910198B00853C23 /* libtorch_cpu.a */, + 37FD7E222910198B00853C23 /* libtorch.a */, + 37FD7E252910198B00853C23 /* libXNNPACK.a */, + 37FD7E1C2910195900853C23 /* libdecoder.a */, + ); + name = Frameworks; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXNativeTarget section */ + 37FD7DFE2910094300853C23 /* WenetDemo */ = { + isa = PBXNativeTarget; + buildConfigurationList = 37FD7E132910094500853C23 /* Build configuration list for PBXNativeTarget "WenetDemo" */; + buildPhases = ( + 37FD7DFB2910094300853C23 /* Sources */, + 37FD7DFC2910094300853C23 /* Frameworks */, + 37FD7DFD2910094300853C23 /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = WenetDemo; + productName = WenetDemo; + productReference = 37FD7DFF2910094300853C23 /* WenetDemo.app */; + productType = "com.apple.product-type.application"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + 37FD7DF72910094300853C23 /* Project object */ = { + isa = PBXProject; + attributes = { + BuildIndependentTargetsInParallel = 1; + LastSwiftUpdateCheck = 1400; + LastUpgradeCheck = 1400; + TargetAttributes = { + 37FD7DFE2910094300853C23 = { + CreatedOnToolsVersion = 14.0.1; + LastSwiftMigration = 1400; + }; + }; + }; + buildConfigurationList = 37FD7DFA2910094300853C23 /* Build configuration list for PBXProject "WenetDemo" */; + compatibilityVersion = "Xcode 14.0"; + developmentRegion = en; + hasScannedForEncodings = 0; + knownRegions = ( + en, + Base, + ); + mainGroup = 37FD7DF62910094300853C23; + productRefGroup = 37FD7E002910094300853C23 /* Products */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + 37FD7DFE2910094300853C23 /* WenetDemo */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXResourcesBuildPhase section */ + 37FD7DFD2910094300853C23 /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 37C64C8B2912ABE900BFCE0B /* units.txt in Resources */, + 37FD7E0F2910094500853C23 /* LaunchScreen.storyboard in Resources */, + 37FD7E0C2910094500853C23 /* Assets.xcassets in Resources */, + 37C64C892912A94B00BFCE0B /* final.zip in Resources */, + 37FD7E0A2910094300853C23 /* Main.storyboard in Resources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXResourcesBuildPhase section */ + +/* Begin PBXSourcesBuildPhase section */ + 37FD7DFB2910094300853C23 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 37FD7E072910094300853C23 /* ViewController.swift in Sources */, + 37FD7E1A291009EC00853C23 /* wenet.mm in Sources */, + 37FD7E032910094300853C23 /* AppDelegate.swift in Sources */, + 37FD7E052910094300853C23 /* SceneDelegate.swift in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin PBXVariantGroup section */ + 37FD7E082910094300853C23 /* Main.storyboard */ = { + isa = PBXVariantGroup; + children = ( + 37FD7E092910094300853C23 /* Base */, + ); + name = Main.storyboard; + sourceTree = ""; + }; + 37FD7E0D2910094500853C23 /* LaunchScreen.storyboard */ = { + isa = PBXVariantGroup; + children = ( + 37FD7E0E2910094500853C23 /* Base */, + ); + name = LaunchScreen.storyboard; + sourceTree = ""; + }; +/* End PBXVariantGroup section */ + +/* Begin XCBuildConfiguration section */ + 37FD7E112910094500853C23 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++20"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_ENABLE_OBJC_WEAK = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = dwarf; + ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_TESTABILITY = YES; + GCC_C_LANGUAGE_STANDARD = gnu11; + GCC_DYNAMIC_NO_PIC = NO; + GCC_NO_COMMON_BLOCKS = YES; + GCC_OPTIMIZATION_LEVEL = 0; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 16.0; + MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; + MTL_FAST_MATH = YES; + ONLY_ACTIVE_ARCH = YES; + SDKROOT = iphoneos; + SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + }; + name = Debug; + }; + 37FD7E122910094500853C23 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++20"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_ENABLE_OBJC_WEAK = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + ENABLE_NS_ASSERTIONS = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; + GCC_C_LANGUAGE_STANDARD = gnu11; + GCC_NO_COMMON_BLOCKS = YES; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 16.0; + MTL_ENABLE_DEBUG_INFO = NO; + MTL_FAST_MATH = YES; + SDKROOT = iphoneos; + SWIFT_COMPILATION_MODE = wholemodule; + SWIFT_OPTIMIZATION_LEVEL = "-O"; + VALIDATE_PRODUCT = YES; + }; + name = Release; + }; + 37FD7E142910094500853C23 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; + CLANG_CXX_LANGUAGE_STANDARD = "c++14"; + CLANG_ENABLE_MODULES = YES; + CODE_SIGN_STYLE = Automatic; + CURRENT_PROJECT_VERSION = 1; + DEVELOPMENT_TEAM = LXGRKDMEQU; + GCC_C_LANGUAGE_STANDARD = gnu11; + GENERATE_INFOPLIST_FILE = YES; + HEADER_SEARCH_PATHS = ( + ../, + "../fc_base/openfst-src/src/include", + "../fc_base/gflags-build/include", + "../fc_base/glog-build", + "../fc_base/glog-src/src", + ../kaldi, + ../build/Pods/LibTorch/install/include, + ); + INFOPLIST_FILE = WenetDemo/Info.plist; + INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES; + INFOPLIST_KEY_UILaunchStoryboardName = LaunchScreen; + INFOPLIST_KEY_UIMainStoryboardFile = Main; + INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; + INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; + IPHONEOS_DEPLOYMENT_TARGET = 14.6; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + ); + LIBRARY_SEARCH_PATHS = ( + "../build/decoder/Debug-iphoneos", + ../build/Pods/LibTorch/install/lib, + "../fc_base/openfst-build/src/lib/Debug-iphoneos", + "../fc_base/gflags-build/Debug-iphoneos", + "../fc_base/glog-build/Debug-iphoneos", + "../build/kaldi/Debug-iphoneos", + "../build/post_processor/Debug-iphoneos", + "../build/utils/Debug-iphoneos", + "../build/frontend/Debug-iphoneos", + ); + MARKETING_VERSION = 1.0; + OTHER_LDFLAGS = ( + "-ObjC", + "-l\"XNNPACK\"", + "-l\"c++\"", + "-l\"c10\"", + "-l\"clog\"", + "-l\"cpuinfo\"", + "-l\"eigen_blas\"", + "-l\"pthreadpool\"", + "-l\"pytorch_qnnpack\"", + "-l\"stdc++\"", + "-l\"torch\"", + "-l\"torch_cpu\"", + "-force_load", + ../build/Pods/LibTorch/install/lib/libtorch.a, + "-force_load", + ../build/Pods/LibTorch/install/lib/libtorch_cpu.a, + "-l\"gflags_nothreads_debug\"", + "-l\"glogd\"", + ); + PRODUCT_BUNDLE_IDENTIFIER = com.wenet.WenetDemo; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_EMIT_LOC_STRINGS = YES; + SWIFT_OBJC_BRIDGING_HEADER = "WenetDemo/wenet/WenetDemo-Bridging-Header.h"; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + SWIFT_VERSION = 5.0; + TARGETED_DEVICE_FAMILY = "1,2"; + }; + name = Debug; + }; + 37FD7E152910094500853C23 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; + CLANG_CXX_LANGUAGE_STANDARD = "c++14"; + CLANG_ENABLE_MODULES = YES; + CODE_SIGN_STYLE = Automatic; + CURRENT_PROJECT_VERSION = 1; + DEVELOPMENT_TEAM = LXGRKDMEQU; + GCC_C_LANGUAGE_STANDARD = gnu11; + GENERATE_INFOPLIST_FILE = YES; + HEADER_SEARCH_PATHS = ( + ../, + "../fc_base/openfst-src/src/include", + "../fc_base/gflags-build/include", + "../fc_base/glog-build", + "../fc_base/glog-src/src", + ../kaldi, + ../build/Pods/LibTorch/install/include, + ); + INFOPLIST_FILE = WenetDemo/Info.plist; + INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES; + INFOPLIST_KEY_UILaunchStoryboardName = LaunchScreen; + INFOPLIST_KEY_UIMainStoryboardFile = Main; + INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; + INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; + IPHONEOS_DEPLOYMENT_TARGET = 14.6; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + ); + LIBRARY_SEARCH_PATHS = ( + "../build/decoder/Release-iphoneos", + ../build/Pods/LibTorch/install/lib, + "../fc_base/openfst-build/src/lib/Release-iphoneos", + "../fc_base/gflags-build/Release-iphoneos", + "../fc_base/glog-build/Release-iphoneos", + "../build/kaldi/Release-iphoneos", + "../build/post_processor/Release-iphoneos", + "../build/utils/Release-iphoneos", + "../build/frontend/Release-iphoneos", + ); + MARKETING_VERSION = 1.0; + OTHER_LDFLAGS = ( + "-ObjC", + "-l\"XNNPACK\"", + "-l\"c++\"", + "-l\"c10\"", + "-l\"clog\"", + "-l\"cpuinfo\"", + "-l\"eigen_blas\"", + "-l\"pthreadpool\"", + "-l\"pytorch_qnnpack\"", + "-l\"stdc++\"", + "-l\"torch\"", + "-l\"torch_cpu\"", + "-force_load", + ../build/Pods/LibTorch/install/lib/libtorch.a, + "-force_load", + ../build/Pods/LibTorch/install/lib/libtorch_cpu.a, + "-l\"gflags_nothreads\"", + "-l\"glog\"", + ); + PRODUCT_BUNDLE_IDENTIFIER = com.wenet.WenetDemo; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_EMIT_LOC_STRINGS = YES; + SWIFT_OBJC_BRIDGING_HEADER = "WenetDemo/wenet/WenetDemo-Bridging-Header.h"; + SWIFT_VERSION = 5.0; + TARGETED_DEVICE_FAMILY = "1,2"; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + 37FD7DFA2910094300853C23 /* Build configuration list for PBXProject "WenetDemo" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 37FD7E112910094500853C23 /* Debug */, + 37FD7E122910094500853C23 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 37FD7E132910094500853C23 /* Build configuration list for PBXNativeTarget "WenetDemo" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 37FD7E142910094500853C23 /* Debug */, + 37FD7E152910094500853C23 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; +/* End XCConfigurationList section */ + }; + rootObject = 37FD7DF72910094300853C23 /* Project object */; +} diff --git a/runtime/ios/WenetDemo/WenetDemo.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/runtime/ios/WenetDemo/WenetDemo.xcodeproj/project.xcworkspace/contents.xcworkspacedata new file mode 100644 index 0000000000..919434a625 --- /dev/null +++ b/runtime/ios/WenetDemo/WenetDemo.xcodeproj/project.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/runtime/ios/WenetDemo/WenetDemo.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/runtime/ios/WenetDemo/WenetDemo.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 0000000000..18d981003d --- /dev/null +++ b/runtime/ios/WenetDemo/WenetDemo.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/runtime/ios/WenetDemo/WenetDemo/AppDelegate.swift b/runtime/ios/WenetDemo/WenetDemo/AppDelegate.swift new file mode 100644 index 0000000000..f75e1ba0de --- /dev/null +++ b/runtime/ios/WenetDemo/WenetDemo/AppDelegate.swift @@ -0,0 +1,34 @@ +// +// AppDelegate.swift +// WenetDemo +// + +import UIKit + +@main +class AppDelegate: UIResponder, UIApplicationDelegate { + + + + func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { + // Override point for customization after application launch. + return true + } + + // MARK: UISceneSession Lifecycle + + func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration { + // Called when a new scene session is being created. + // Use this method to select a configuration to create the new scene with. + return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role) + } + + func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set) { + // Called when the user discards a scene session. + // If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions. + // Use this method to release any resources that were specific to the discarded scenes, as they will not return. + } + + +} + diff --git a/runtime/ios/WenetDemo/WenetDemo/Assets.xcassets/AccentColor.colorset/Contents.json b/runtime/ios/WenetDemo/WenetDemo/Assets.xcassets/AccentColor.colorset/Contents.json new file mode 100644 index 0000000000..eb87897008 --- /dev/null +++ b/runtime/ios/WenetDemo/WenetDemo/Assets.xcassets/AccentColor.colorset/Contents.json @@ -0,0 +1,11 @@ +{ + "colors" : [ + { + "idiom" : "universal" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/runtime/ios/WenetDemo/WenetDemo/Assets.xcassets/AppIcon.appiconset/Contents.json b/runtime/ios/WenetDemo/WenetDemo/Assets.xcassets/AppIcon.appiconset/Contents.json new file mode 100644 index 0000000000..13613e3ee1 --- /dev/null +++ b/runtime/ios/WenetDemo/WenetDemo/Assets.xcassets/AppIcon.appiconset/Contents.json @@ -0,0 +1,13 @@ +{ + "images" : [ + { + "idiom" : "universal", + "platform" : "ios", + "size" : "1024x1024" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/runtime/ios/WenetDemo/WenetDemo/Assets.xcassets/Contents.json b/runtime/ios/WenetDemo/WenetDemo/Assets.xcassets/Contents.json new file mode 100644 index 0000000000..73c00596a7 --- /dev/null +++ b/runtime/ios/WenetDemo/WenetDemo/Assets.xcassets/Contents.json @@ -0,0 +1,6 @@ +{ + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/runtime/ios/WenetDemo/WenetDemo/Base.lproj/LaunchScreen.storyboard b/runtime/ios/WenetDemo/WenetDemo/Base.lproj/LaunchScreen.storyboard new file mode 100644 index 0000000000..865e9329f3 --- /dev/null +++ b/runtime/ios/WenetDemo/WenetDemo/Base.lproj/LaunchScreen.storyboard @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/runtime/ios/WenetDemo/WenetDemo/Base.lproj/Main.storyboard b/runtime/ios/WenetDemo/WenetDemo/Base.lproj/Main.storyboard new file mode 100644 index 0000000000..24468cc4fa --- /dev/null +++ b/runtime/ios/WenetDemo/WenetDemo/Base.lproj/Main.storyboard @@ -0,0 +1,55 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/runtime/ios/WenetDemo/WenetDemo/Info.plist b/runtime/ios/WenetDemo/WenetDemo/Info.plist new file mode 100644 index 0000000000..b2039f5877 --- /dev/null +++ b/runtime/ios/WenetDemo/WenetDemo/Info.plist @@ -0,0 +1,27 @@ + + + + + UIApplicationSceneManifest + + UIApplicationSupportsMultipleScenes + + UISceneConfigurations + + UIWindowSceneSessionRoleApplication + + + UISceneConfigurationName + Default Configuration + UISceneDelegateClassName + $(PRODUCT_MODULE_NAME).SceneDelegate + UISceneStoryboardFile + Main + + + + + NSMicrophoneUsageDescription + Need microphone access for recording speech + + diff --git a/runtime/ios/WenetDemo/WenetDemo/SceneDelegate.swift b/runtime/ios/WenetDemo/WenetDemo/SceneDelegate.swift new file mode 100644 index 0000000000..2b2e3ec253 --- /dev/null +++ b/runtime/ios/WenetDemo/WenetDemo/SceneDelegate.swift @@ -0,0 +1,50 @@ +// +// SceneDelegate.swift +// WenetDemo +// + +import UIKit + +class SceneDelegate: UIResponder, UIWindowSceneDelegate { + + var window: UIWindow? + + + func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) { + // Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`. + // If using a storyboard, the `window` property will automatically be initialized and attached to the scene. + // This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead). + guard let _ = (scene as? UIWindowScene) else { return } + } + + func sceneDidDisconnect(_ scene: UIScene) { + // Called as the scene is being released by the system. + // This occurs shortly after the scene enters the background, or when its session is discarded. + // Release any resources associated with this scene that can be re-created the next time the scene connects. + // The scene may re-connect later, as its session was not necessarily discarded (see `application:didDiscardSceneSessions` instead). + } + + func sceneDidBecomeActive(_ scene: UIScene) { + // Called when the scene has moved from an inactive state to an active state. + // Use this method to restart any tasks that were paused (or not yet started) when the scene was inactive. + } + + func sceneWillResignActive(_ scene: UIScene) { + // Called when the scene will move from an active state to an inactive state. + // This may occur due to temporary interruptions (ex. an incoming phone call). + } + + func sceneWillEnterForeground(_ scene: UIScene) { + // Called as the scene transitions from the background to the foreground. + // Use this method to undo the changes made on entering the background. + } + + func sceneDidEnterBackground(_ scene: UIScene) { + // Called as the scene transitions from the foreground to the background. + // Use this method to save data, release shared resources, and store enough scene-specific state information + // to restore the scene back to its current state. + } + + +} + diff --git a/runtime/ios/WenetDemo/WenetDemo/ViewController.swift b/runtime/ios/WenetDemo/WenetDemo/ViewController.swift new file mode 100644 index 0000000000..e0fc13ee3c --- /dev/null +++ b/runtime/ios/WenetDemo/WenetDemo/ViewController.swift @@ -0,0 +1,116 @@ +// +// ViewController.swift +// WenetDemo +// + +import UIKit +import AVFoundation + +class ViewController: UIViewController { + + @IBOutlet weak var label: UILabel! + @IBOutlet weak var button: UIButton! + + var wenetModel: Wenet? + var audioEngine: AVAudioEngine? + var startRecord: Bool? + private var workItem: DispatchWorkItem? + + override func viewDidLoad() { + super.viewDidLoad() + // Do any additional setup after loading the view. + + initModel() + + initRecorder() + } + + func initModel() { + let modelPath = Bundle.main.path(forResource: "final", ofType: "zip") + let dictPath = Bundle.main.path(forResource: "units", ofType: "txt") + wenetModel = Wenet(modelPath:modelPath, dictPath:dictPath)! + + wenetModel?.reset() + } + + func initRecorder() { + startRecord = false + + audioEngine = AVAudioEngine() + let inputNode = self.audioEngine?.inputNode + let bus = 0 + let inputFormat = inputNode?.outputFormat(forBus: bus) + let outputFormat = AVAudioFormat(commonFormat: .pcmFormatFloat32, sampleRate: 16000, channels: 1, interleaved: false)! + let converter = AVAudioConverter(from: inputFormat!, to: outputFormat)! + inputNode!.installTap(onBus: bus, bufferSize: 1024, format: inputFormat) { (buffer: AVAudioPCMBuffer, when: AVAudioTime) in + var newBufferAvailable = true + + let inputCallback: AVAudioConverterInputBlock = { inNumPackets, outStatus in + if newBufferAvailable { + outStatus.pointee = .haveData + newBufferAvailable = false + + return buffer + } else { + outStatus.pointee = .noDataNow + return nil + } + } + + let convertedBuffer = AVAudioPCMBuffer(pcmFormat: outputFormat, frameCapacity: AVAudioFrameCount(outputFormat.sampleRate) * buffer.frameLength / AVAudioFrameCount(buffer.format.sampleRate))! + + var error: NSError? + let status = converter.convert(to: convertedBuffer, error: &error, withInputFrom: inputCallback) + + // 16000 Hz buffer + let actualSampleCount = Int(convertedBuffer.frameLength) + guard let floatChannelData = convertedBuffer.floatChannelData else { return } + + self.wenetModel?.acceptWaveForm(floatChannelData[0], Int32(actualSampleCount)) + } + } + + @IBAction func btnClicked(_ sender: Any) { + if(!startRecord!) { + //Clear result + self.setResult(text: "") + + //Reset model + self.wenetModel?.reset() + + //Start record + do { + try self.audioEngine?.start() + } catch let error as NSError { + print("Got an error starting audioEngine: \(error.domain), \(error)") + } + + //Start decode thread + workItem = DispatchWorkItem { + while(!self.workItem!.isCancelled) { + self.wenetModel?.decode() + DispatchQueue.main.sync { + self.setResult(text: (self.wenetModel?.get_result())!) + } + } + } + DispatchQueue.global().async(execute: workItem!) + + startRecord = true + button.setTitle("Stop Record", for: UIControl.State.normal) + } else { + //Stop record + self.audioEngine?.stop() + + //Stop decode thread + workItem!.cancel() + + startRecord = false + button.setTitle("Start Record", for: UIControl.State.normal) + } + } + + @objc func setResult(text: String) { + label.text = text + } +} diff --git a/runtime/ios/WenetDemo/WenetDemo/model/.gitkeep b/runtime/ios/WenetDemo/WenetDemo/model/.gitkeep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/runtime/ios/WenetDemo/WenetDemo/wenet/WenetDemo-Bridging-Header.h b/runtime/ios/WenetDemo/WenetDemo/wenet/WenetDemo-Bridging-Header.h new file mode 100644 index 0000000000..0f78a05fb8 --- /dev/null +++ b/runtime/ios/WenetDemo/WenetDemo/wenet/WenetDemo-Bridging-Header.h @@ -0,0 +1,5 @@ +// +// Use this file to import your target's public headers that you would like to expose to Swift. +// + +#import "wenet.h" diff --git a/runtime/ios/WenetDemo/WenetDemo/wenet/wenet.h b/runtime/ios/WenetDemo/WenetDemo/wenet/wenet.h new file mode 100644 index 0000000000..9bf1c1c16a --- /dev/null +++ b/runtime/ios/WenetDemo/WenetDemo/wenet/wenet.h @@ -0,0 +1,26 @@ +// +// wenet.h +// WenetDemo + +#ifndef wenet_h +#define wenet_h + +#include + +#import + +@interface Wenet : NSObject + +- (nullable instancetype)initWithModelPath:(NSString*)modelPath DictPath:(NSString*)dictPath; + +- (void)reset; + +- (void)acceptWaveForm: (float*)pcm: (int)size; + +- (void)decode; + +- (NSString*)get_result; + +@end + +#endif /* wenet_h */ diff --git a/runtime/ios/WenetDemo/WenetDemo/wenet/wenet.mm b/runtime/ios/WenetDemo/WenetDemo/wenet/wenet.mm new file mode 100644 index 0000000000..4f782e3693 --- /dev/null +++ b/runtime/ios/WenetDemo/WenetDemo/wenet/wenet.mm @@ -0,0 +1,114 @@ +// +// wenet.cmm +// WenetDemo + +#include "wenet.h" + +#include "decoder/asr_decoder.h" +#include "decoder/ios_asr_model.h" +#include "frontend/feature_pipeline.h" +#include "frontend/wav.h" +#include "post_processor/post_processor.h" +#include "utils/log.h" +#include "utils/string.h" + +using namespace wenet; + +@implementation Wenet { +@protected + std::shared_ptr decode_config; + std::shared_ptr feature_config; + std::shared_ptr feature_pipeline; + std::shared_ptr decoder; + std::shared_ptr resource; + DecodeState state; + std::string total_result; +} + +- (nullable instancetype)initWithModelPath:(NSString*)modelPath DictPath:(NSString*)dictPath { + self = [super init]; + if (self) { + try { + auto qengines = at::globalContext().supportedQEngines(); + if (std::find(qengines.begin(), qengines.end(), at::QEngine::QNNPACK) != qengines.end()) { + at::globalContext().setQEngine(at::QEngine::QNNPACK); + } + auto model = std::make_shared(); + model->Read(modelPath.UTF8String); + resource = std::make_shared(); + resource->model = model; + resource->symbol_table = std::shared_ptr( + fst::SymbolTable::ReadText(dictPath.UTF8String)); + + PostProcessOptions post_process_opts; + resource->post_processor = std::make_shared(post_process_opts); + + feature_config = std::make_shared(80, 16000); + feature_pipeline = std::make_shared(*feature_config); + + decode_config = std::make_shared(); + decode_config->chunk_size = 16; + decoder = std::make_shared(feature_pipeline, resource, *decode_config); + + state = kEndBatch; + } catch (const std::exception& exception) { + NSLog(@"%s", exception.what()); + return nil; + } + } + + return self; +} + +- (void)reset { + decoder->Reset(); + state = kEndBatch; + total_result = ""; +} + +- (void)acceptWaveForm: (float*)pcm: (int)size { + auto* float_pcm = new float[size]; + for (size_t i = 0; i < size; i++) { + float_pcm[i] = pcm[i] * 65535; + } + feature_pipeline->AcceptWaveform(float_pcm, size); +} + +- (void)decode { + state = decoder->Decode(); + if (state == kEndFeats || state == kEndpoint) { + decoder->Rescoring(); + } + + std::string result; + if (decoder->DecodedSomething()) { + result = decoder->result()[0].sentence; + } + + if (state == kEndFeats) { + LOG(INFO) << "wenet endfeats final result: " << result; + NSLog(@"wenet endfeats final result: %s", result.c_str()); + total_result += result; + } else if (state == kEndpoint) { + LOG(INFO) << "wenet endpoint final result: " << result; + NSLog(@"wenet endpoint final result: %s", result.c_str()); + total_result += result + ","; + decoder->ResetContinuousDecoding(); + } else { + if (decoder->DecodedSomething()) { + LOG(INFO) << "wenet partial result: " << result; + } + } +} + +- (NSString*)get_result { + std::string result; + if (decoder->DecodedSomething()) { + result = decoder->result()[0].sentence; + } + LOG(INFO) << "wenet ui result: " << total_result + result; + NSLog(@"wenet ui result: %s", (total_result + result).c_str()); + return [NSString stringWithUTF8String:(total_result + result).c_str()]; +} + +@end diff --git a/runtime/ios/api b/runtime/ios/api new file mode 120000 index 0000000000..5c1acaccc3 --- /dev/null +++ b/runtime/ios/api @@ -0,0 +1 @@ +../core/api \ No newline at end of file diff --git a/runtime/ios/bin b/runtime/ios/bin new file mode 120000 index 0000000000..938df72152 --- /dev/null +++ b/runtime/ios/bin @@ -0,0 +1 @@ +../core/bin \ No newline at end of file diff --git a/runtime/ios/build/Podfile b/runtime/ios/build/Podfile new file mode 100644 index 0000000000..66bd745d1d --- /dev/null +++ b/runtime/ios/build/Podfile @@ -0,0 +1,4 @@ +platform :ios, '14.3' +target 'decoder_main' do + pod 'LibTorch', '~>1.9.0' +end diff --git a/runtime/ios/cmake b/runtime/ios/cmake new file mode 120000 index 0000000000..17afee87dc --- /dev/null +++ b/runtime/ios/cmake @@ -0,0 +1 @@ +../core/cmake \ No newline at end of file diff --git a/runtime/ios/decoder b/runtime/ios/decoder new file mode 120000 index 0000000000..3088ea48b2 --- /dev/null +++ b/runtime/ios/decoder @@ -0,0 +1 @@ +../core/decoder \ No newline at end of file diff --git a/runtime/ios/frontend b/runtime/ios/frontend new file mode 120000 index 0000000000..0292335d13 --- /dev/null +++ b/runtime/ios/frontend @@ -0,0 +1 @@ +../core/frontend \ No newline at end of file diff --git a/runtime/ios/kaldi b/runtime/ios/kaldi new file mode 120000 index 0000000000..764a9d445d --- /dev/null +++ b/runtime/ios/kaldi @@ -0,0 +1 @@ +../core/kaldi \ No newline at end of file diff --git a/runtime/ios/patch b/runtime/ios/patch new file mode 120000 index 0000000000..69789fa5e4 --- /dev/null +++ b/runtime/ios/patch @@ -0,0 +1 @@ +../core/patch \ No newline at end of file diff --git a/runtime/ios/post_processor b/runtime/ios/post_processor new file mode 120000 index 0000000000..4e434a5cca --- /dev/null +++ b/runtime/ios/post_processor @@ -0,0 +1 @@ +../core/post_processor \ No newline at end of file diff --git a/runtime/ios/test b/runtime/ios/test new file mode 120000 index 0000000000..e60cf87a7f --- /dev/null +++ b/runtime/ios/test @@ -0,0 +1 @@ +../core/test \ No newline at end of file diff --git a/runtime/ios/toolchains b/runtime/ios/toolchains new file mode 120000 index 0000000000..c4b2ab76f7 --- /dev/null +++ b/runtime/ios/toolchains @@ -0,0 +1 @@ +../core/toolchains \ No newline at end of file diff --git a/runtime/ios/utils b/runtime/ios/utils new file mode 120000 index 0000000000..9e19e7af5a --- /dev/null +++ b/runtime/ios/utils @@ -0,0 +1 @@ +../core/utils \ No newline at end of file diff --git a/runtime/ios/websocket b/runtime/ios/websocket new file mode 120000 index 0000000000..18f5de12cf --- /dev/null +++ b/runtime/ios/websocket @@ -0,0 +1 @@ +../core/websocket \ No newline at end of file From e06d89d7084670306e378f676927ba9c5195ebbd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=A9=AC=E4=B8=B9?= Date: Thu, 10 Nov 2022 22:31:40 +0800 Subject: [PATCH 02/13] Clean up code and add license information --- runtime/core/decoder/ios_asr_model.cc | 53 +----------- runtime/core/decoder/ios_asr_model.h | 6 +- .../core/patch/openfst/src/bin/CMakeLists.txt | 86 ------------------- runtime/ios/CMakeLists.txt | 10 --- runtime/ios/README.md | 2 +- .../ios/WenetDemo/WenetDemo/AppDelegate.swift | 12 +++ .../WenetDemo/WenetDemo/SceneDelegate.swift | 1 + .../WenetDemo/WenetDemo/ViewController.swift | 58 ++++++++----- runtime/ios/WenetDemo/WenetDemo/wenet/wenet.h | 13 +++ .../ios/WenetDemo/WenetDemo/wenet/wenet.mm | 29 +++++-- runtime/ios/api | 1 - runtime/ios/bin | 1 - runtime/ios/websocket | 1 - 13 files changed, 87 insertions(+), 186 deletions(-) delete mode 120000 runtime/ios/api delete mode 120000 runtime/ios/bin delete mode 120000 runtime/ios/websocket diff --git a/runtime/core/decoder/ios_asr_model.cc b/runtime/core/decoder/ios_asr_model.cc index 259b8f4c64..c88a0a6646 100644 --- a/runtime/core/decoder/ios_asr_model.cc +++ b/runtime/core/decoder/ios_asr_model.cc @@ -1,5 +1,6 @@ // Copyright (c) 2020 Mobvoi Inc (Binbin Zhang, Di Wu) // 2022 Binbin Zhang (binbzha@qq.com) +// 2022 Dan Ma (1067837450@qq.com) // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -22,32 +23,11 @@ #include #include "torch/script.h" -//#include "torch/torch.h" namespace wenet { -void IosAsrModel::InitEngineThreads(int num_threads) { - // For multi-thread performance - //at::set_num_threads(num_threads); - // Note: Do not call the set_num_interop_threads function more than once. - // Please see https://github.com/pytorch/pytorch/blob/master/aten/src/ATen/ - // ParallelThreadPoolNative.cpp#L54-L56 - //at::set_num_interop_threads(1); - //VLOG(1) << "Num intra-op threads: " << at::get_num_threads(); - //VLOG(1) << "Num inter-op threads: " << at::get_num_interop_threads(); -} - void IosAsrModel::Read(const std::string& model_path) { torch::DeviceType device = at::kCPU; -#ifdef USE_GPU - if (!torch::cuda::is_available()) { - VLOG(1) << "CUDA is not available! Please check your GPU settings"; - throw std::runtime_error("CUDA is not available!"); - } else { - VLOG(1) << "CUDA available! Running on GPU"; - device = at::kCUDA; - } -#endif torch::jit::script::Module model = torch::jit::load(model_path, device); model_ = std::make_shared(std::move(model)); torch::NoGradGuard no_grad; @@ -136,11 +116,6 @@ void IosAsrModel::ForwardEncoderFunc( } // 2. Encoder chunk forward -#ifdef USE_GPU - feats = feats.to(at::kCUDA); - att_cache_ = att_cache_.to(at::kCUDA); - cnn_cache_ = cnn_cache_.to(at::kCUDA); -#endif int required_cache_size = chunk_size_ * num_left_chunks_; torch::NoGradGuard no_grad; std::vector inputs = {feats, offset_, required_cache_size, @@ -150,29 +125,15 @@ void IosAsrModel::ForwardEncoderFunc( auto outputs = model_->get_method("forward_encoder_chunk")(inputs).toTuple()->elements(); CHECK_EQ(outputs.size(), 3); -#ifdef USE_GPU - torch::Tensor chunk_out = outputs[0].toTensor().to(at::kCPU); - att_cache_ = outputs[1].toTensor().to(at::kCPU); - cnn_cache_ = outputs[2].toTensor().to(at::kCPU); -#else torch::Tensor chunk_out = outputs[0].toTensor(); att_cache_ = outputs[1].toTensor(); cnn_cache_ = outputs[2].toTensor(); -#endif offset_ += chunk_out.size(1); // The first dimension of returned value is for batchsize, which is 1 -#ifdef USE_GPU - chunk_out = chunk_out.to(at::kCUDA); - torch::Tensor ctc_log_probs = - model_->run_method("ctc_activation", chunk_out).toTensor(); - ctc_log_probs = ctc_log_probs.to(at::kCPU)[0]; - encoder_outs_.push_back(std::move(chunk_out.to(at::kCPU))); -#else torch::Tensor ctc_log_probs = model_->run_method("ctc_activation", chunk_out).toTensor()[0]; encoder_outs_.push_back(std::move(chunk_out)); -#endif // Copy to output int num_outputs = ctc_log_probs.size(0); @@ -233,23 +194,15 @@ void IosAsrModel::AttentionRescoring( // Step 2: Forward attention decoder by hyps and corresponding encoder_outs_ torch::Tensor encoder_out = torch::cat(encoder_outs_, 1); -#ifdef USE_GPU - hyps_tensor = hyps_tensor.to(at::kCUDA); - hyps_length = hyps_length.to(at::kCUDA); - encoder_out = encoder_out.to(at::kCUDA); -#endif auto outputs = model_ ->run_method("forward_attention_decoder", hyps_tensor, hyps_length, encoder_out, reverse_weight) .toTuple() ->elements(); -#ifdef USE_GPU - auto probs = outputs[0].toTensor().to(at::kCPU); - auto r_probs = outputs[1].toTensor().to(at::kCPU); -#else + auto probs = outputs[0].toTensor(); auto r_probs = outputs[1].toTensor(); -#endif + CHECK_EQ(probs.size(0), num_hyps); CHECK_EQ(probs.size(1), max_hyps_len); diff --git a/runtime/core/decoder/ios_asr_model.h b/runtime/core/decoder/ios_asr_model.h index 0b9f504063..c55a538da5 100644 --- a/runtime/core/decoder/ios_asr_model.h +++ b/runtime/core/decoder/ios_asr_model.h @@ -1,5 +1,6 @@ // Copyright (c) 2020 Mobvoi Inc (Binbin Zhang, Di Wu) // 2022 Binbin Zhang (binbzha@qq.com) +// 2022 Dan Ma (1067837450@qq.com) // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -22,7 +23,6 @@ #include #include "torch/script.h" -//#include "torch/torch.h" #include "decoder/asr_model.h" #include "utils/utils.h" @@ -30,10 +30,6 @@ namespace wenet { class IosAsrModel : public AsrModel { - public: - // Note: Do not call the InitEngineThreads function more than once. - static void InitEngineThreads(int num_threads = 1); - public: using TorchModule = torch::jit::script::Module; IosAsrModel() = default; diff --git a/runtime/core/patch/openfst/src/bin/CMakeLists.txt b/runtime/core/patch/openfst/src/bin/CMakeLists.txt index 92ff3824db..e69de29bb2 100644 --- a/runtime/core/patch/openfst/src/bin/CMakeLists.txt +++ b/runtime/core/patch/openfst/src/bin/CMakeLists.txt @@ -1,86 +0,0 @@ -function (add_executable2 _name) - add_executable(${ARGV}) - if (TARGET ${_name}) - target_link_libraries(${_name} fstscript fst ${CMAKE_DL_LIBS}) - set_target_properties(${_name} PROPERTIES FOLDER bin) - endif() - - install(TARGETS ${_name} RUNTIME DESTINATION . BUNDLE DESTINATION bin) -endfunction() - -include_directories(../include ../script/) - -add_executable2(fstarcsort fstarcsort-main.cc fstarcsort.cc) - -add_executable2(fstclosure fstclosure-main.cc fstclosure.cc) - -add_executable2(fstcompile fstcompile-main.cc fstcompile.cc) - -add_executable2(fstcompose fstcompose-main.cc fstcompose.cc) - -add_executable2(fstconcat fstconcat-main.cc fstconcat.cc) - -add_executable2(fstconnect fstconnect-main.cc fstconnect.cc) - -add_executable2(fstconvert fstconvert-main.cc fstconvert.cc) - -add_executable2(fstdeterminize fstdeterminize-main.cc fstdeterminize.cc) - -add_executable2(fstdifference fstdifference-main.cc fstdifference.cc) - -add_executable2(fstdisambiguate fstdisambiguate-main.cc fstdisambiguate.cc) - -add_executable2(fstdraw fstdraw-main.cc fstdraw.cc) - -add_executable2(fstencode fstencode-main.cc fstencode.cc) - -add_executable2(fstepsnormalize fstepsnormalize-main.cc fstepsnormalize.cc) - -add_executable2(fstequal fstequal-main.cc fstequal.cc) - -add_executable2(fstequivalent fstequivalent-main.cc fstequivalent.cc) - -add_executable2(fstinfo fstinfo-main.cc fstinfo.cc) - -add_executable2(fstintersect fstintersect-main.cc fstintersect.cc) - -add_executable2(fstinvert fstinvert-main.cc fstinvert.cc) - -add_executable2(fstisomorphic fstisomorphic-main.cc fstisomorphic.cc) - -add_executable2(fstmap fstmap-main.cc fstmap.cc) - -add_executable2(fstminimize fstminimize-main.cc fstminimize.cc) - -add_executable2(fstprint fstprint-main.cc fstprint.cc) - -add_executable2(fstproject fstproject-main.cc fstproject.cc) - -add_executable2(fstprune fstprune-main.cc fstprune.cc) - -add_executable2(fstpush fstpush-main.cc fstpush.cc) - -add_executable2(fstrandgen fstrandgen-main.cc fstrandgen.cc) - -add_executable2(fstrelabel fstrelabel-main.cc fstrelabel.cc) - -add_executable2(fstreplace fstreplace-main.cc fstreplace.cc) - -add_executable2(fstreverse fstreverse-main.cc fstreverse.cc) - -add_executable2(fstreweight fstreweight-main.cc fstreweight.cc) - -add_executable2(fstrmepsilon fstrmepsilon-main.cc fstrmepsilon.cc) - -add_executable2(fstshortestdistance fstshortestdistance-main.cc fstshortestdistance.cc) - -add_executable2(fstshortestpath fstshortestpath-main.cc fstshortestpath.cc) - -add_executable2(fstsymbols fstsymbols-main.cc fstsymbols.cc) - -add_executable2(fstsynchronize fstsynchronize-main.cc fstsynchronize.cc) - -add_executable2(fsttopsort fsttopsort-main.cc fsttopsort.cc) - -add_executable2(fstunion fstunion-main.cc fstunion.cc) - diff --git a/runtime/ios/CMakeLists.txt b/runtime/ios/CMakeLists.txt index 9fd328997a..567ee97834 100644 --- a/runtime/ios/CMakeLists.txt +++ b/runtime/ios/CMakeLists.txt @@ -51,13 +51,6 @@ add_subdirectory(frontend) add_subdirectory(post_processor) add_subdirectory(kaldi) # kaldi: wfst based decoder add_subdirectory(decoder) -add_subdirectory(api) - -# Optionally, you can build with websocket -if(WEBSOCKET) - include(boost) - add_subdirectory(websocket) -endif() # Optionally, you can build with gRPC if(GRPC) @@ -65,9 +58,6 @@ if(GRPC) add_subdirectory(grpc) endif() -# Build all bins -add_subdirectory(bin) - # Unit Test if(BUILD_TESTING) include(gtest) diff --git a/runtime/ios/README.md b/runtime/ios/README.md index 4fca5c1ffc..dec19a606e 100644 --- a/runtime/ios/README.md +++ b/runtime/ios/README.md @@ -12,7 +12,7 @@ pod install ### 2) Remove executable targets in wenet project -Open wenet.xcworkspace in runtime/ios/build folder with Xcode, remove all 47 executable targets in wenet project and Pods-decoder_main target in Pods project, leave static library targets only, close Xcode to save workspace. +Open wenet.xcodeproj in runtime/ios/build folder with Xcode, remove all 6 executable targets, leave static library targets only, close Xcode to save workspace. ### 3) Build static libraries diff --git a/runtime/ios/WenetDemo/WenetDemo/AppDelegate.swift b/runtime/ios/WenetDemo/WenetDemo/AppDelegate.swift index f75e1ba0de..6f99512fc5 100644 --- a/runtime/ios/WenetDemo/WenetDemo/AppDelegate.swift +++ b/runtime/ios/WenetDemo/WenetDemo/AppDelegate.swift @@ -1,7 +1,19 @@ +// Copyright (c) 2022 Dan Ma (1067837450@qq.com) // // AppDelegate.swift // WenetDemo // +// 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. import UIKit diff --git a/runtime/ios/WenetDemo/WenetDemo/SceneDelegate.swift b/runtime/ios/WenetDemo/WenetDemo/SceneDelegate.swift index 2b2e3ec253..b2db94181b 100644 --- a/runtime/ios/WenetDemo/WenetDemo/SceneDelegate.swift +++ b/runtime/ios/WenetDemo/WenetDemo/SceneDelegate.swift @@ -1,3 +1,4 @@ +// Copyright (c) 2022 Dan Ma (1067837450@qq.com) // // SceneDelegate.swift // WenetDemo diff --git a/runtime/ios/WenetDemo/WenetDemo/ViewController.swift b/runtime/ios/WenetDemo/WenetDemo/ViewController.swift index e0fc13ee3c..5efada2962 100644 --- a/runtime/ios/WenetDemo/WenetDemo/ViewController.swift +++ b/runtime/ios/WenetDemo/WenetDemo/ViewController.swift @@ -1,41 +1,53 @@ +// Copyright (c) 2022 Dan Ma (1067837450@qq.com) // // ViewController.swift // WenetDemo // +// 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. import UIKit import AVFoundation class ViewController: UIViewController { - + @IBOutlet weak var label: UILabel! @IBOutlet weak var button: UIButton! - + var wenetModel: Wenet? var audioEngine: AVAudioEngine? var startRecord: Bool? private var workItem: DispatchWorkItem? - + override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view. - + initModel() - + initRecorder() } - + func initModel() { let modelPath = Bundle.main.path(forResource: "final", ofType: "zip") let dictPath = Bundle.main.path(forResource: "units", ofType: "txt") wenetModel = Wenet(modelPath:modelPath, dictPath:dictPath)! - + wenetModel?.reset() } - + func initRecorder() { startRecord = false - + audioEngine = AVAudioEngine() let inputNode = self.audioEngine?.inputNode let bus = 0 @@ -44,47 +56,47 @@ class ViewController: UIViewController { let converter = AVAudioConverter(from: inputFormat!, to: outputFormat)! inputNode!.installTap(onBus: bus, bufferSize: 1024, format: inputFormat) { (buffer: AVAudioPCMBuffer, when: AVAudioTime) in var newBufferAvailable = true - + let inputCallback: AVAudioConverterInputBlock = { inNumPackets, outStatus in if newBufferAvailable { outStatus.pointee = .haveData newBufferAvailable = false - + return buffer } else { outStatus.pointee = .noDataNow return nil } } - + let convertedBuffer = AVAudioPCMBuffer(pcmFormat: outputFormat, frameCapacity: AVAudioFrameCount(outputFormat.sampleRate) * buffer.frameLength / AVAudioFrameCount(buffer.format.sampleRate))! - + var error: NSError? let status = converter.convert(to: convertedBuffer, error: &error, withInputFrom: inputCallback) - + // 16000 Hz buffer let actualSampleCount = Int(convertedBuffer.frameLength) guard let floatChannelData = convertedBuffer.floatChannelData else { return } - + self.wenetModel?.acceptWaveForm(floatChannelData[0], Int32(actualSampleCount)) } } - + @IBAction func btnClicked(_ sender: Any) { if(!startRecord!) { //Clear result self.setResult(text: "") - + //Reset model self.wenetModel?.reset() - + //Start record do { try self.audioEngine?.start() } catch let error as NSError { print("Got an error starting audioEngine: \(error.domain), \(error)") } - + //Start decode thread workItem = DispatchWorkItem { while(!self.workItem!.isCancelled) { @@ -95,21 +107,21 @@ class ViewController: UIViewController { } } DispatchQueue.global().async(execute: workItem!) - + startRecord = true button.setTitle("Stop Record", for: UIControl.State.normal) } else { //Stop record self.audioEngine?.stop() - + //Stop decode thread workItem!.cancel() - + startRecord = false button.setTitle("Start Record", for: UIControl.State.normal) } } - + @objc func setResult(text: String) { label.text = text } diff --git a/runtime/ios/WenetDemo/WenetDemo/wenet/wenet.h b/runtime/ios/WenetDemo/WenetDemo/wenet/wenet.h index 9bf1c1c16a..cca7391784 100644 --- a/runtime/ios/WenetDemo/WenetDemo/wenet/wenet.h +++ b/runtime/ios/WenetDemo/WenetDemo/wenet/wenet.h @@ -1,6 +1,19 @@ +// Copyright (c) 2022 Dan Ma (1067837450@qq.com) // // wenet.h // WenetDemo +// +// 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. #ifndef wenet_h #define wenet_h diff --git a/runtime/ios/WenetDemo/WenetDemo/wenet/wenet.mm b/runtime/ios/WenetDemo/WenetDemo/wenet/wenet.mm index 4f782e3693..cf1df11a58 100644 --- a/runtime/ios/WenetDemo/WenetDemo/wenet/wenet.mm +++ b/runtime/ios/WenetDemo/WenetDemo/wenet/wenet.mm @@ -1,6 +1,19 @@ +// Copyright (c) 2022 Dan Ma (1067837450@qq.com) // -// wenet.cmm +// wenet.mm // WenetDemo +// +// 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. #include "wenet.h" @@ -39,24 +52,24 @@ - (nullable instancetype)initWithModelPath:(NSString*)modelPath DictPath:(NSStri resource->model = model; resource->symbol_table = std::shared_ptr( fst::SymbolTable::ReadText(dictPath.UTF8String)); - + PostProcessOptions post_process_opts; resource->post_processor = std::make_shared(post_process_opts); - + feature_config = std::make_shared(80, 16000); feature_pipeline = std::make_shared(*feature_config); - + decode_config = std::make_shared(); decode_config->chunk_size = 16; decoder = std::make_shared(feature_pipeline, resource, *decode_config); - + state = kEndBatch; } catch (const std::exception& exception) { NSLog(@"%s", exception.what()); return nil; } } - + return self; } @@ -79,12 +92,12 @@ - (void)decode { if (state == kEndFeats || state == kEndpoint) { decoder->Rescoring(); } - + std::string result; if (decoder->DecodedSomething()) { result = decoder->result()[0].sentence; } - + if (state == kEndFeats) { LOG(INFO) << "wenet endfeats final result: " << result; NSLog(@"wenet endfeats final result: %s", result.c_str()); diff --git a/runtime/ios/api b/runtime/ios/api deleted file mode 120000 index 5c1acaccc3..0000000000 --- a/runtime/ios/api +++ /dev/null @@ -1 +0,0 @@ -../core/api \ No newline at end of file diff --git a/runtime/ios/bin b/runtime/ios/bin deleted file mode 120000 index 938df72152..0000000000 --- a/runtime/ios/bin +++ /dev/null @@ -1 +0,0 @@ -../core/bin \ No newline at end of file diff --git a/runtime/ios/websocket b/runtime/ios/websocket deleted file mode 120000 index 18f5de12cf..0000000000 --- a/runtime/ios/websocket +++ /dev/null @@ -1 +0,0 @@ -../core/websocket \ No newline at end of file From bef7e401605ae9ae3d31370d06f155631026fd8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=A9=AC=E4=B8=B9?= Date: Thu, 10 Nov 2022 22:38:39 +0800 Subject: [PATCH 03/13] Update Podfile --- runtime/ios/build/Podfile | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/runtime/ios/build/Podfile b/runtime/ios/build/Podfile index 66bd745d1d..f839cc082e 100644 --- a/runtime/ios/build/Podfile +++ b/runtime/ios/build/Podfile @@ -1,4 +1,2 @@ platform :ios, '14.3' -target 'decoder_main' do - pod 'LibTorch', '~>1.9.0' -end +pod 'LibTorch', '~>1.9.0' From 7bff527b1d350b2a5b73d4ef3ce791a29c4364c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=A9=AC=E4=B8=B9?= Date: Thu, 10 Nov 2022 23:09:37 +0800 Subject: [PATCH 04/13] Add license --- .../WenetDemo/wenet/WenetDemo-Bridging-Header.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/runtime/ios/WenetDemo/WenetDemo/wenet/WenetDemo-Bridging-Header.h b/runtime/ios/WenetDemo/WenetDemo/wenet/WenetDemo-Bridging-Header.h index 0f78a05fb8..fe205e4b22 100644 --- a/runtime/ios/WenetDemo/WenetDemo/wenet/WenetDemo-Bridging-Header.h +++ b/runtime/ios/WenetDemo/WenetDemo/wenet/WenetDemo-Bridging-Header.h @@ -1,5 +1,17 @@ +// Copyright (c) 2022 Dan Ma (1067837450@qq.com) // // Use this file to import your target's public headers that you would like to expose to Swift. // +// 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. #import "wenet.h" From 082c19e123088f9f8034e69c4e0e317dfa8a642b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=A9=AC=E4=B8=B9?= Date: Thu, 10 Nov 2022 23:18:25 +0800 Subject: [PATCH 05/13] Fix lint tab check --- .../WenetDemo.xcodeproj/project.pbxproj | 1054 ++++++++--------- .../xcshareddata/IDEWorkspaceChecks.plist | 4 +- runtime/ios/WenetDemo/WenetDemo/Info.plist | 38 +- 3 files changed, 548 insertions(+), 548 deletions(-) diff --git a/runtime/ios/WenetDemo/WenetDemo.xcodeproj/project.pbxproj b/runtime/ios/WenetDemo/WenetDemo.xcodeproj/project.pbxproj index e567a04468..9563d20b6c 100644 --- a/runtime/ios/WenetDemo/WenetDemo.xcodeproj/project.pbxproj +++ b/runtime/ios/WenetDemo/WenetDemo.xcodeproj/project.pbxproj @@ -1,563 +1,563 @@ // !$*UTF8*$! { - archiveVersion = 1; - classes = { - }; - objectVersion = 56; - objects = { + archiveVersion = 1; + classes = { + }; + objectVersion = 56; + objects = { /* Begin PBXBuildFile section */ - 374FEB34291019EE00513F88 /* libeigen_blas.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 37FD7E1E2910198A00853C23 /* libeigen_blas.a */; }; - 37C64C892912A94B00BFCE0B /* final.zip in Resources */ = {isa = PBXBuildFile; fileRef = 37C64C882912A94A00BFCE0B /* final.zip */; }; - 37C64C8B2912ABE900BFCE0B /* units.txt in Resources */ = {isa = PBXBuildFile; fileRef = 37C64C8A2912ABE900BFCE0B /* units.txt */; }; - 37C64C8F2912ADDD00BFCE0B /* libfst.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 37C64C8E2912ADDD00BFCE0B /* libfst.a */; }; - 37C64C942912AF7F00BFCE0B /* libkaldi-decoder.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 37C64C8C2912AD3300BFCE0B /* libkaldi-decoder.a */; }; - 37C64C962912AFC900BFCE0B /* libpost_processor.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 37C64C952912AFC900BFCE0B /* libpost_processor.a */; }; - 37C64C982912B06800BFCE0B /* libutils.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 37C64C972912B06800BFCE0B /* libutils.a */; }; - 37C64C9A2912B0A000BFCE0B /* libfrontend.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 37C64C992912B0A000BFCE0B /* libfrontend.a */; }; - 37FD7E032910094300853C23 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 37FD7E022910094300853C23 /* AppDelegate.swift */; }; - 37FD7E052910094300853C23 /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 37FD7E042910094300853C23 /* SceneDelegate.swift */; }; - 37FD7E072910094300853C23 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 37FD7E062910094300853C23 /* ViewController.swift */; }; - 37FD7E0A2910094300853C23 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 37FD7E082910094300853C23 /* Main.storyboard */; }; - 37FD7E0C2910094500853C23 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 37FD7E0B2910094500853C23 /* Assets.xcassets */; }; - 37FD7E0F2910094500853C23 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 37FD7E0D2910094500853C23 /* LaunchScreen.storyboard */; }; - 37FD7E1A291009EC00853C23 /* wenet.mm in Sources */ = {isa = PBXBuildFile; fileRef = 37FD7E18291009EC00853C23 /* wenet.mm */; }; - 37FD7E1D2910195900853C23 /* libdecoder.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 37FD7E1C2910195900853C23 /* libdecoder.a */; }; - 37FD7E282910198B00853C23 /* libpthreadpool.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 37FD7E1F2910198B00853C23 /* libpthreadpool.a */; }; - 37FD7E292910198B00853C23 /* libc10.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 37FD7E202910198B00853C23 /* libc10.a */; }; - 37FD7E2A2910198B00853C23 /* libtorch_cpu.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 37FD7E212910198B00853C23 /* libtorch_cpu.a */; }; - 37FD7E2B2910198B00853C23 /* libtorch.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 37FD7E222910198B00853C23 /* libtorch.a */; }; - 37FD7E2C2910198B00853C23 /* libclog.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 37FD7E232910198B00853C23 /* libclog.a */; }; - 37FD7E2D2910198B00853C23 /* libcpuinfo.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 37FD7E242910198B00853C23 /* libcpuinfo.a */; }; - 37FD7E2E2910198C00853C23 /* libXNNPACK.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 37FD7E252910198B00853C23 /* libXNNPACK.a */; }; - 37FD7E2F2910198C00853C23 /* libpytorch_qnnpack.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 37FD7E262910198B00853C23 /* libpytorch_qnnpack.a */; }; + 374FEB34291019EE00513F88 /* libeigen_blas.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 37FD7E1E2910198A00853C23 /* libeigen_blas.a */; }; + 37C64C892912A94B00BFCE0B /* final.zip in Resources */ = {isa = PBXBuildFile; fileRef = 37C64C882912A94A00BFCE0B /* final.zip */; }; + 37C64C8B2912ABE900BFCE0B /* units.txt in Resources */ = {isa = PBXBuildFile; fileRef = 37C64C8A2912ABE900BFCE0B /* units.txt */; }; + 37C64C8F2912ADDD00BFCE0B /* libfst.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 37C64C8E2912ADDD00BFCE0B /* libfst.a */; }; + 37C64C942912AF7F00BFCE0B /* libkaldi-decoder.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 37C64C8C2912AD3300BFCE0B /* libkaldi-decoder.a */; }; + 37C64C962912AFC900BFCE0B /* libpost_processor.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 37C64C952912AFC900BFCE0B /* libpost_processor.a */; }; + 37C64C982912B06800BFCE0B /* libutils.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 37C64C972912B06800BFCE0B /* libutils.a */; }; + 37C64C9A2912B0A000BFCE0B /* libfrontend.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 37C64C992912B0A000BFCE0B /* libfrontend.a */; }; + 37FD7E032910094300853C23 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 37FD7E022910094300853C23 /* AppDelegate.swift */; }; + 37FD7E052910094300853C23 /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 37FD7E042910094300853C23 /* SceneDelegate.swift */; }; + 37FD7E072910094300853C23 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 37FD7E062910094300853C23 /* ViewController.swift */; }; + 37FD7E0A2910094300853C23 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 37FD7E082910094300853C23 /* Main.storyboard */; }; + 37FD7E0C2910094500853C23 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 37FD7E0B2910094500853C23 /* Assets.xcassets */; }; + 37FD7E0F2910094500853C23 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 37FD7E0D2910094500853C23 /* LaunchScreen.storyboard */; }; + 37FD7E1A291009EC00853C23 /* wenet.mm in Sources */ = {isa = PBXBuildFile; fileRef = 37FD7E18291009EC00853C23 /* wenet.mm */; }; + 37FD7E1D2910195900853C23 /* libdecoder.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 37FD7E1C2910195900853C23 /* libdecoder.a */; }; + 37FD7E282910198B00853C23 /* libpthreadpool.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 37FD7E1F2910198B00853C23 /* libpthreadpool.a */; }; + 37FD7E292910198B00853C23 /* libc10.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 37FD7E202910198B00853C23 /* libc10.a */; }; + 37FD7E2A2910198B00853C23 /* libtorch_cpu.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 37FD7E212910198B00853C23 /* libtorch_cpu.a */; }; + 37FD7E2B2910198B00853C23 /* libtorch.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 37FD7E222910198B00853C23 /* libtorch.a */; }; + 37FD7E2C2910198B00853C23 /* libclog.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 37FD7E232910198B00853C23 /* libclog.a */; }; + 37FD7E2D2910198B00853C23 /* libcpuinfo.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 37FD7E242910198B00853C23 /* libcpuinfo.a */; }; + 37FD7E2E2910198C00853C23 /* libXNNPACK.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 37FD7E252910198B00853C23 /* libXNNPACK.a */; }; + 37FD7E2F2910198C00853C23 /* libpytorch_qnnpack.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 37FD7E262910198B00853C23 /* libpytorch_qnnpack.a */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ - 373FDD93291BE53D00DF4BEA /* libglog.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libglog.a; path = "../fc_base/glog-build/Release-iphoneos/libglog.a"; sourceTree = ""; }; - 373FDD95291BE5A800DF4BEA /* libgflags_nothreads.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libgflags_nothreads.a; path = "../fc_base/gflags-build/Release-iphoneos/libgflags_nothreads.a"; sourceTree = ""; }; - 37C64C882912A94A00BFCE0B /* final.zip */ = {isa = PBXFileReference; lastKnownFileType = archive.zip; path = final.zip; sourceTree = ""; }; - 37C64C8A2912ABE900BFCE0B /* units.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = units.txt; sourceTree = ""; }; - 37C64C8C2912AD3300BFCE0B /* libkaldi-decoder.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = "libkaldi-decoder.a"; path = "../build/kaldi/Debug-iphoneos/libkaldi-decoder.a"; sourceTree = ""; }; - 37C64C8E2912ADDD00BFCE0B /* libfst.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libfst.a; path = "../fc_base/openfst-build/src/lib/Debug-iphoneos/libfst.a"; sourceTree = ""; }; - 37C64C902912AE2B00BFCE0B /* libgflags_nothreads_debug.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libgflags_nothreads_debug.a; path = "../fc_base/gflags-build/Debug-iphoneos/libgflags_nothreads_debug.a"; sourceTree = ""; }; - 37C64C922912AE7E00BFCE0B /* libglogd.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libglogd.a; path = "../fc_base/glog-build/Debug-iphoneos/libglogd.a"; sourceTree = ""; }; - 37C64C952912AFC900BFCE0B /* libpost_processor.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libpost_processor.a; path = "../build/post_processor/Debug-iphoneos/libpost_processor.a"; sourceTree = ""; }; - 37C64C972912B06800BFCE0B /* libutils.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libutils.a; path = "../build/utils/Debug-iphoneos/libutils.a"; sourceTree = ""; }; - 37C64C992912B0A000BFCE0B /* libfrontend.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libfrontend.a; path = "../build/frontend/Debug-iphoneos/libfrontend.a"; sourceTree = ""; }; - 37FD7DFF2910094300853C23 /* WenetDemo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = WenetDemo.app; sourceTree = BUILT_PRODUCTS_DIR; }; - 37FD7E022910094300853C23 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; - 37FD7E042910094300853C23 /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = ""; }; - 37FD7E062910094300853C23 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; - 37FD7E092910094300853C23 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; - 37FD7E0B2910094500853C23 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; - 37FD7E0E2910094500853C23 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; - 37FD7E102910094500853C23 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; - 37FD7E17291009EC00853C23 /* WenetDemo-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "WenetDemo-Bridging-Header.h"; sourceTree = ""; }; - 37FD7E18291009EC00853C23 /* wenet.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = wenet.mm; sourceTree = ""; }; - 37FD7E19291009EC00853C23 /* wenet.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = wenet.h; sourceTree = ""; }; - 37FD7E1C2910195900853C23 /* libdecoder.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libdecoder.a; path = "../wenet/runtime/ios/build/decoder/Debug-iphoneos/libdecoder.a"; sourceTree = ""; }; - 37FD7E1E2910198A00853C23 /* libeigen_blas.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libeigen_blas.a; path = ../wenet/runtime/ios/build/Pods/LibTorch/install/lib/libeigen_blas.a; sourceTree = ""; }; - 37FD7E1F2910198B00853C23 /* libpthreadpool.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libpthreadpool.a; path = ../wenet/runtime/ios/build/Pods/LibTorch/install/lib/libpthreadpool.a; sourceTree = ""; }; - 37FD7E202910198B00853C23 /* libc10.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libc10.a; path = ../wenet/runtime/ios/build/Pods/LibTorch/install/lib/libc10.a; sourceTree = ""; }; - 37FD7E212910198B00853C23 /* libtorch_cpu.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libtorch_cpu.a; path = ../wenet/runtime/ios/build/Pods/LibTorch/install/lib/libtorch_cpu.a; sourceTree = ""; }; - 37FD7E222910198B00853C23 /* libtorch.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libtorch.a; path = ../wenet/runtime/ios/build/Pods/LibTorch/install/lib/libtorch.a; sourceTree = ""; }; - 37FD7E232910198B00853C23 /* libclog.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libclog.a; path = ../wenet/runtime/ios/build/Pods/LibTorch/install/lib/libclog.a; sourceTree = ""; }; - 37FD7E242910198B00853C23 /* libcpuinfo.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libcpuinfo.a; path = ../wenet/runtime/ios/build/Pods/LibTorch/install/lib/libcpuinfo.a; sourceTree = ""; }; - 37FD7E252910198B00853C23 /* libXNNPACK.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libXNNPACK.a; path = ../wenet/runtime/ios/build/Pods/LibTorch/install/lib/libXNNPACK.a; sourceTree = ""; }; - 37FD7E262910198B00853C23 /* libpytorch_qnnpack.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libpytorch_qnnpack.a; path = ../wenet/runtime/ios/build/Pods/LibTorch/install/lib/libpytorch_qnnpack.a; sourceTree = ""; }; + 373FDD93291BE53D00DF4BEA /* libglog.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libglog.a; path = "../fc_base/glog-build/Release-iphoneos/libglog.a"; sourceTree = ""; }; + 373FDD95291BE5A800DF4BEA /* libgflags_nothreads.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libgflags_nothreads.a; path = "../fc_base/gflags-build/Release-iphoneos/libgflags_nothreads.a"; sourceTree = ""; }; + 37C64C882912A94A00BFCE0B /* final.zip */ = {isa = PBXFileReference; lastKnownFileType = archive.zip; path = final.zip; sourceTree = ""; }; + 37C64C8A2912ABE900BFCE0B /* units.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = units.txt; sourceTree = ""; }; + 37C64C8C2912AD3300BFCE0B /* libkaldi-decoder.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = "libkaldi-decoder.a"; path = "../build/kaldi/Debug-iphoneos/libkaldi-decoder.a"; sourceTree = ""; }; + 37C64C8E2912ADDD00BFCE0B /* libfst.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libfst.a; path = "../fc_base/openfst-build/src/lib/Debug-iphoneos/libfst.a"; sourceTree = ""; }; + 37C64C902912AE2B00BFCE0B /* libgflags_nothreads_debug.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libgflags_nothreads_debug.a; path = "../fc_base/gflags-build/Debug-iphoneos/libgflags_nothreads_debug.a"; sourceTree = ""; }; + 37C64C922912AE7E00BFCE0B /* libglogd.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libglogd.a; path = "../fc_base/glog-build/Debug-iphoneos/libglogd.a"; sourceTree = ""; }; + 37C64C952912AFC900BFCE0B /* libpost_processor.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libpost_processor.a; path = "../build/post_processor/Debug-iphoneos/libpost_processor.a"; sourceTree = ""; }; + 37C64C972912B06800BFCE0B /* libutils.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libutils.a; path = "../build/utils/Debug-iphoneos/libutils.a"; sourceTree = ""; }; + 37C64C992912B0A000BFCE0B /* libfrontend.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libfrontend.a; path = "../build/frontend/Debug-iphoneos/libfrontend.a"; sourceTree = ""; }; + 37FD7DFF2910094300853C23 /* WenetDemo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = WenetDemo.app; sourceTree = BUILT_PRODUCTS_DIR; }; + 37FD7E022910094300853C23 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; + 37FD7E042910094300853C23 /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = ""; }; + 37FD7E062910094300853C23 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; + 37FD7E092910094300853C23 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; + 37FD7E0B2910094500853C23 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; + 37FD7E0E2910094500853C23 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; + 37FD7E102910094500853C23 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + 37FD7E17291009EC00853C23 /* WenetDemo-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "WenetDemo-Bridging-Header.h"; sourceTree = ""; }; + 37FD7E18291009EC00853C23 /* wenet.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = wenet.mm; sourceTree = ""; }; + 37FD7E19291009EC00853C23 /* wenet.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = wenet.h; sourceTree = ""; }; + 37FD7E1C2910195900853C23 /* libdecoder.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libdecoder.a; path = "../wenet/runtime/ios/build/decoder/Debug-iphoneos/libdecoder.a"; sourceTree = ""; }; + 37FD7E1E2910198A00853C23 /* libeigen_blas.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libeigen_blas.a; path = ../wenet/runtime/ios/build/Pods/LibTorch/install/lib/libeigen_blas.a; sourceTree = ""; }; + 37FD7E1F2910198B00853C23 /* libpthreadpool.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libpthreadpool.a; path = ../wenet/runtime/ios/build/Pods/LibTorch/install/lib/libpthreadpool.a; sourceTree = ""; }; + 37FD7E202910198B00853C23 /* libc10.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libc10.a; path = ../wenet/runtime/ios/build/Pods/LibTorch/install/lib/libc10.a; sourceTree = ""; }; + 37FD7E212910198B00853C23 /* libtorch_cpu.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libtorch_cpu.a; path = ../wenet/runtime/ios/build/Pods/LibTorch/install/lib/libtorch_cpu.a; sourceTree = ""; }; + 37FD7E222910198B00853C23 /* libtorch.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libtorch.a; path = ../wenet/runtime/ios/build/Pods/LibTorch/install/lib/libtorch.a; sourceTree = ""; }; + 37FD7E232910198B00853C23 /* libclog.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libclog.a; path = ../wenet/runtime/ios/build/Pods/LibTorch/install/lib/libclog.a; sourceTree = ""; }; + 37FD7E242910198B00853C23 /* libcpuinfo.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libcpuinfo.a; path = ../wenet/runtime/ios/build/Pods/LibTorch/install/lib/libcpuinfo.a; sourceTree = ""; }; + 37FD7E252910198B00853C23 /* libXNNPACK.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libXNNPACK.a; path = ../wenet/runtime/ios/build/Pods/LibTorch/install/lib/libXNNPACK.a; sourceTree = ""; }; + 37FD7E262910198B00853C23 /* libpytorch_qnnpack.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libpytorch_qnnpack.a; path = ../wenet/runtime/ios/build/Pods/LibTorch/install/lib/libpytorch_qnnpack.a; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ - 37FD7DFC2910094300853C23 /* Frameworks */ = { - isa = PBXFrameworksBuildPhase; - buildActionMask = 2147483647; - files = ( - 37C64C9A2912B0A000BFCE0B /* libfrontend.a in Frameworks */, - 37C64C982912B06800BFCE0B /* libutils.a in Frameworks */, - 37C64C962912AFC900BFCE0B /* libpost_processor.a in Frameworks */, - 37C64C942912AF7F00BFCE0B /* libkaldi-decoder.a in Frameworks */, - 37C64C8F2912ADDD00BFCE0B /* libfst.a in Frameworks */, - 374FEB34291019EE00513F88 /* libeigen_blas.a in Frameworks */, - 37FD7E282910198B00853C23 /* libpthreadpool.a in Frameworks */, - 37FD7E292910198B00853C23 /* libc10.a in Frameworks */, - 37FD7E2A2910198B00853C23 /* libtorch_cpu.a in Frameworks */, - 37FD7E2B2910198B00853C23 /* libtorch.a in Frameworks */, - 37FD7E2C2910198B00853C23 /* libclog.a in Frameworks */, - 37FD7E2D2910198B00853C23 /* libcpuinfo.a in Frameworks */, - 37FD7E2E2910198C00853C23 /* libXNNPACK.a in Frameworks */, - 37FD7E2F2910198C00853C23 /* libpytorch_qnnpack.a in Frameworks */, - 37FD7E1D2910195900853C23 /* libdecoder.a in Frameworks */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; + 37FD7DFC2910094300853C23 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + 37C64C9A2912B0A000BFCE0B /* libfrontend.a in Frameworks */, + 37C64C982912B06800BFCE0B /* libutils.a in Frameworks */, + 37C64C962912AFC900BFCE0B /* libpost_processor.a in Frameworks */, + 37C64C942912AF7F00BFCE0B /* libkaldi-decoder.a in Frameworks */, + 37C64C8F2912ADDD00BFCE0B /* libfst.a in Frameworks */, + 374FEB34291019EE00513F88 /* libeigen_blas.a in Frameworks */, + 37FD7E282910198B00853C23 /* libpthreadpool.a in Frameworks */, + 37FD7E292910198B00853C23 /* libc10.a in Frameworks */, + 37FD7E2A2910198B00853C23 /* libtorch_cpu.a in Frameworks */, + 37FD7E2B2910198B00853C23 /* libtorch.a in Frameworks */, + 37FD7E2C2910198B00853C23 /* libclog.a in Frameworks */, + 37FD7E2D2910198B00853C23 /* libcpuinfo.a in Frameworks */, + 37FD7E2E2910198C00853C23 /* libXNNPACK.a in Frameworks */, + 37FD7E2F2910198C00853C23 /* libpytorch_qnnpack.a in Frameworks */, + 37FD7E1D2910195900853C23 /* libdecoder.a in Frameworks */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ - 37C64C812912A21300BFCE0B /* model */ = { - isa = PBXGroup; - children = ( - 37C64C8A2912ABE900BFCE0B /* units.txt */, - 37C64C882912A94A00BFCE0B /* final.zip */, - ); - path = model; - sourceTree = ""; - }; - 37FD7DF62910094300853C23 = { - isa = PBXGroup; - children = ( - 37FD7E012910094300853C23 /* WenetDemo */, - 37FD7E002910094300853C23 /* Products */, - 37FD7E1B2910195900853C23 /* Frameworks */, - ); - sourceTree = ""; - }; - 37FD7E002910094300853C23 /* Products */ = { - isa = PBXGroup; - children = ( - 37FD7DFF2910094300853C23 /* WenetDemo.app */, - ); - name = Products; - sourceTree = ""; - }; - 37FD7E012910094300853C23 /* WenetDemo */ = { - isa = PBXGroup; - children = ( - 37C64C812912A21300BFCE0B /* model */, - 37FD7E16291009B900853C23 /* wenet */, - 37FD7E022910094300853C23 /* AppDelegate.swift */, - 37FD7E042910094300853C23 /* SceneDelegate.swift */, - 37FD7E062910094300853C23 /* ViewController.swift */, - 37FD7E082910094300853C23 /* Main.storyboard */, - 37FD7E0B2910094500853C23 /* Assets.xcassets */, - 37FD7E0D2910094500853C23 /* LaunchScreen.storyboard */, - 37FD7E102910094500853C23 /* Info.plist */, - ); - path = WenetDemo; - sourceTree = ""; - }; - 37FD7E16291009B900853C23 /* wenet */ = { - isa = PBXGroup; - children = ( - 37FD7E18291009EC00853C23 /* wenet.mm */, - 37FD7E19291009EC00853C23 /* wenet.h */, - 37FD7E17291009EC00853C23 /* WenetDemo-Bridging-Header.h */, - ); - path = wenet; - sourceTree = ""; - }; - 37FD7E1B2910195900853C23 /* Frameworks */ = { - isa = PBXGroup; - children = ( - 373FDD95291BE5A800DF4BEA /* libgflags_nothreads.a */, - 373FDD93291BE53D00DF4BEA /* libglog.a */, - 37C64C992912B0A000BFCE0B /* libfrontend.a */, - 37C64C972912B06800BFCE0B /* libutils.a */, - 37C64C952912AFC900BFCE0B /* libpost_processor.a */, - 37C64C922912AE7E00BFCE0B /* libglogd.a */, - 37C64C902912AE2B00BFCE0B /* libgflags_nothreads_debug.a */, - 37C64C8E2912ADDD00BFCE0B /* libfst.a */, - 37C64C8C2912AD3300BFCE0B /* libkaldi-decoder.a */, - 37FD7E202910198B00853C23 /* libc10.a */, - 37FD7E232910198B00853C23 /* libclog.a */, - 37FD7E242910198B00853C23 /* libcpuinfo.a */, - 37FD7E1E2910198A00853C23 /* libeigen_blas.a */, - 37FD7E1F2910198B00853C23 /* libpthreadpool.a */, - 37FD7E262910198B00853C23 /* libpytorch_qnnpack.a */, - 37FD7E212910198B00853C23 /* libtorch_cpu.a */, - 37FD7E222910198B00853C23 /* libtorch.a */, - 37FD7E252910198B00853C23 /* libXNNPACK.a */, - 37FD7E1C2910195900853C23 /* libdecoder.a */, - ); - name = Frameworks; - sourceTree = ""; - }; + 37C64C812912A21300BFCE0B /* model */ = { + isa = PBXGroup; + children = ( + 37C64C8A2912ABE900BFCE0B /* units.txt */, + 37C64C882912A94A00BFCE0B /* final.zip */, + ); + path = model; + sourceTree = ""; + }; + 37FD7DF62910094300853C23 = { + isa = PBXGroup; + children = ( + 37FD7E012910094300853C23 /* WenetDemo */, + 37FD7E002910094300853C23 /* Products */, + 37FD7E1B2910195900853C23 /* Frameworks */, + ); + sourceTree = ""; + }; + 37FD7E002910094300853C23 /* Products */ = { + isa = PBXGroup; + children = ( + 37FD7DFF2910094300853C23 /* WenetDemo.app */, + ); + name = Products; + sourceTree = ""; + }; + 37FD7E012910094300853C23 /* WenetDemo */ = { + isa = PBXGroup; + children = ( + 37C64C812912A21300BFCE0B /* model */, + 37FD7E16291009B900853C23 /* wenet */, + 37FD7E022910094300853C23 /* AppDelegate.swift */, + 37FD7E042910094300853C23 /* SceneDelegate.swift */, + 37FD7E062910094300853C23 /* ViewController.swift */, + 37FD7E082910094300853C23 /* Main.storyboard */, + 37FD7E0B2910094500853C23 /* Assets.xcassets */, + 37FD7E0D2910094500853C23 /* LaunchScreen.storyboard */, + 37FD7E102910094500853C23 /* Info.plist */, + ); + path = WenetDemo; + sourceTree = ""; + }; + 37FD7E16291009B900853C23 /* wenet */ = { + isa = PBXGroup; + children = ( + 37FD7E18291009EC00853C23 /* wenet.mm */, + 37FD7E19291009EC00853C23 /* wenet.h */, + 37FD7E17291009EC00853C23 /* WenetDemo-Bridging-Header.h */, + ); + path = wenet; + sourceTree = ""; + }; + 37FD7E1B2910195900853C23 /* Frameworks */ = { + isa = PBXGroup; + children = ( + 373FDD95291BE5A800DF4BEA /* libgflags_nothreads.a */, + 373FDD93291BE53D00DF4BEA /* libglog.a */, + 37C64C992912B0A000BFCE0B /* libfrontend.a */, + 37C64C972912B06800BFCE0B /* libutils.a */, + 37C64C952912AFC900BFCE0B /* libpost_processor.a */, + 37C64C922912AE7E00BFCE0B /* libglogd.a */, + 37C64C902912AE2B00BFCE0B /* libgflags_nothreads_debug.a */, + 37C64C8E2912ADDD00BFCE0B /* libfst.a */, + 37C64C8C2912AD3300BFCE0B /* libkaldi-decoder.a */, + 37FD7E202910198B00853C23 /* libc10.a */, + 37FD7E232910198B00853C23 /* libclog.a */, + 37FD7E242910198B00853C23 /* libcpuinfo.a */, + 37FD7E1E2910198A00853C23 /* libeigen_blas.a */, + 37FD7E1F2910198B00853C23 /* libpthreadpool.a */, + 37FD7E262910198B00853C23 /* libpytorch_qnnpack.a */, + 37FD7E212910198B00853C23 /* libtorch_cpu.a */, + 37FD7E222910198B00853C23 /* libtorch.a */, + 37FD7E252910198B00853C23 /* libXNNPACK.a */, + 37FD7E1C2910195900853C23 /* libdecoder.a */, + ); + name = Frameworks; + sourceTree = ""; + }; /* End PBXGroup section */ /* Begin PBXNativeTarget section */ - 37FD7DFE2910094300853C23 /* WenetDemo */ = { - isa = PBXNativeTarget; - buildConfigurationList = 37FD7E132910094500853C23 /* Build configuration list for PBXNativeTarget "WenetDemo" */; - buildPhases = ( - 37FD7DFB2910094300853C23 /* Sources */, - 37FD7DFC2910094300853C23 /* Frameworks */, - 37FD7DFD2910094300853C23 /* Resources */, - ); - buildRules = ( - ); - dependencies = ( - ); - name = WenetDemo; - productName = WenetDemo; - productReference = 37FD7DFF2910094300853C23 /* WenetDemo.app */; - productType = "com.apple.product-type.application"; - }; + 37FD7DFE2910094300853C23 /* WenetDemo */ = { + isa = PBXNativeTarget; + buildConfigurationList = 37FD7E132910094500853C23 /* Build configuration list for PBXNativeTarget "WenetDemo" */; + buildPhases = ( + 37FD7DFB2910094300853C23 /* Sources */, + 37FD7DFC2910094300853C23 /* Frameworks */, + 37FD7DFD2910094300853C23 /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = WenetDemo; + productName = WenetDemo; + productReference = 37FD7DFF2910094300853C23 /* WenetDemo.app */; + productType = "com.apple.product-type.application"; + }; /* End PBXNativeTarget section */ /* Begin PBXProject section */ - 37FD7DF72910094300853C23 /* Project object */ = { - isa = PBXProject; - attributes = { - BuildIndependentTargetsInParallel = 1; - LastSwiftUpdateCheck = 1400; - LastUpgradeCheck = 1400; - TargetAttributes = { - 37FD7DFE2910094300853C23 = { - CreatedOnToolsVersion = 14.0.1; - LastSwiftMigration = 1400; - }; - }; - }; - buildConfigurationList = 37FD7DFA2910094300853C23 /* Build configuration list for PBXProject "WenetDemo" */; - compatibilityVersion = "Xcode 14.0"; - developmentRegion = en; - hasScannedForEncodings = 0; - knownRegions = ( - en, - Base, - ); - mainGroup = 37FD7DF62910094300853C23; - productRefGroup = 37FD7E002910094300853C23 /* Products */; - projectDirPath = ""; - projectRoot = ""; - targets = ( - 37FD7DFE2910094300853C23 /* WenetDemo */, - ); - }; + 37FD7DF72910094300853C23 /* Project object */ = { + isa = PBXProject; + attributes = { + BuildIndependentTargetsInParallel = 1; + LastSwiftUpdateCheck = 1400; + LastUpgradeCheck = 1400; + TargetAttributes = { + 37FD7DFE2910094300853C23 = { + CreatedOnToolsVersion = 14.0.1; + LastSwiftMigration = 1400; + }; + }; + }; + buildConfigurationList = 37FD7DFA2910094300853C23 /* Build configuration list for PBXProject "WenetDemo" */; + compatibilityVersion = "Xcode 14.0"; + developmentRegion = en; + hasScannedForEncodings = 0; + knownRegions = ( + en, + Base, + ); + mainGroup = 37FD7DF62910094300853C23; + productRefGroup = 37FD7E002910094300853C23 /* Products */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + 37FD7DFE2910094300853C23 /* WenetDemo */, + ); + }; /* End PBXProject section */ /* Begin PBXResourcesBuildPhase section */ - 37FD7DFD2910094300853C23 /* Resources */ = { - isa = PBXResourcesBuildPhase; - buildActionMask = 2147483647; - files = ( - 37C64C8B2912ABE900BFCE0B /* units.txt in Resources */, - 37FD7E0F2910094500853C23 /* LaunchScreen.storyboard in Resources */, - 37FD7E0C2910094500853C23 /* Assets.xcassets in Resources */, - 37C64C892912A94B00BFCE0B /* final.zip in Resources */, - 37FD7E0A2910094300853C23 /* Main.storyboard in Resources */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; + 37FD7DFD2910094300853C23 /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 37C64C8B2912ABE900BFCE0B /* units.txt in Resources */, + 37FD7E0F2910094500853C23 /* LaunchScreen.storyboard in Resources */, + 37FD7E0C2910094500853C23 /* Assets.xcassets in Resources */, + 37C64C892912A94B00BFCE0B /* final.zip in Resources */, + 37FD7E0A2910094300853C23 /* Main.storyboard in Resources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; /* End PBXResourcesBuildPhase section */ /* Begin PBXSourcesBuildPhase section */ - 37FD7DFB2910094300853C23 /* Sources */ = { - isa = PBXSourcesBuildPhase; - buildActionMask = 2147483647; - files = ( - 37FD7E072910094300853C23 /* ViewController.swift in Sources */, - 37FD7E1A291009EC00853C23 /* wenet.mm in Sources */, - 37FD7E032910094300853C23 /* AppDelegate.swift in Sources */, - 37FD7E052910094300853C23 /* SceneDelegate.swift in Sources */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; + 37FD7DFB2910094300853C23 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 37FD7E072910094300853C23 /* ViewController.swift in Sources */, + 37FD7E1A291009EC00853C23 /* wenet.mm in Sources */, + 37FD7E032910094300853C23 /* AppDelegate.swift in Sources */, + 37FD7E052910094300853C23 /* SceneDelegate.swift in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; /* End PBXSourcesBuildPhase section */ /* Begin PBXVariantGroup section */ - 37FD7E082910094300853C23 /* Main.storyboard */ = { - isa = PBXVariantGroup; - children = ( - 37FD7E092910094300853C23 /* Base */, - ); - name = Main.storyboard; - sourceTree = ""; - }; - 37FD7E0D2910094500853C23 /* LaunchScreen.storyboard */ = { - isa = PBXVariantGroup; - children = ( - 37FD7E0E2910094500853C23 /* Base */, - ); - name = LaunchScreen.storyboard; - sourceTree = ""; - }; + 37FD7E082910094300853C23 /* Main.storyboard */ = { + isa = PBXVariantGroup; + children = ( + 37FD7E092910094300853C23 /* Base */, + ); + name = Main.storyboard; + sourceTree = ""; + }; + 37FD7E0D2910094500853C23 /* LaunchScreen.storyboard */ = { + isa = PBXVariantGroup; + children = ( + 37FD7E0E2910094500853C23 /* Base */, + ); + name = LaunchScreen.storyboard; + sourceTree = ""; + }; /* End PBXVariantGroup section */ /* Begin XCBuildConfiguration section */ - 37FD7E112910094500853C23 /* Debug */ = { - isa = XCBuildConfiguration; - buildSettings = { - ALWAYS_SEARCH_USER_PATHS = NO; - CLANG_ANALYZER_NONNULL = YES; - CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; - CLANG_CXX_LANGUAGE_STANDARD = "gnu++20"; - CLANG_ENABLE_MODULES = YES; - CLANG_ENABLE_OBJC_ARC = YES; - CLANG_ENABLE_OBJC_WEAK = YES; - CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; - CLANG_WARN_BOOL_CONVERSION = YES; - CLANG_WARN_COMMA = YES; - CLANG_WARN_CONSTANT_CONVERSION = YES; - CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; - CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; - CLANG_WARN_DOCUMENTATION_COMMENTS = YES; - CLANG_WARN_EMPTY_BODY = YES; - CLANG_WARN_ENUM_CONVERSION = YES; - CLANG_WARN_INFINITE_RECURSION = YES; - CLANG_WARN_INT_CONVERSION = YES; - CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; - CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; - CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; - CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; - CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; - CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; - CLANG_WARN_STRICT_PROTOTYPES = YES; - CLANG_WARN_SUSPICIOUS_MOVE = YES; - CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; - CLANG_WARN_UNREACHABLE_CODE = YES; - CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; - COPY_PHASE_STRIP = NO; - DEBUG_INFORMATION_FORMAT = dwarf; - ENABLE_STRICT_OBJC_MSGSEND = YES; - ENABLE_TESTABILITY = YES; - GCC_C_LANGUAGE_STANDARD = gnu11; - GCC_DYNAMIC_NO_PIC = NO; - GCC_NO_COMMON_BLOCKS = YES; - GCC_OPTIMIZATION_LEVEL = 0; - GCC_PREPROCESSOR_DEFINITIONS = ( - "DEBUG=1", - "$(inherited)", - ); - GCC_WARN_64_TO_32_BIT_CONVERSION = YES; - GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; - GCC_WARN_UNDECLARED_SELECTOR = YES; - GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; - GCC_WARN_UNUSED_FUNCTION = YES; - GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 16.0; - MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; - MTL_FAST_MATH = YES; - ONLY_ACTIVE_ARCH = YES; - SDKROOT = iphoneos; - SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; - SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - }; - name = Debug; - }; - 37FD7E122910094500853C23 /* Release */ = { - isa = XCBuildConfiguration; - buildSettings = { - ALWAYS_SEARCH_USER_PATHS = NO; - CLANG_ANALYZER_NONNULL = YES; - CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; - CLANG_CXX_LANGUAGE_STANDARD = "gnu++20"; - CLANG_ENABLE_MODULES = YES; - CLANG_ENABLE_OBJC_ARC = YES; - CLANG_ENABLE_OBJC_WEAK = YES; - CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; - CLANG_WARN_BOOL_CONVERSION = YES; - CLANG_WARN_COMMA = YES; - CLANG_WARN_CONSTANT_CONVERSION = YES; - CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; - CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; - CLANG_WARN_DOCUMENTATION_COMMENTS = YES; - CLANG_WARN_EMPTY_BODY = YES; - CLANG_WARN_ENUM_CONVERSION = YES; - CLANG_WARN_INFINITE_RECURSION = YES; - CLANG_WARN_INT_CONVERSION = YES; - CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; - CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; - CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; - CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; - CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; - CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; - CLANG_WARN_STRICT_PROTOTYPES = YES; - CLANG_WARN_SUSPICIOUS_MOVE = YES; - CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; - CLANG_WARN_UNREACHABLE_CODE = YES; - CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; - COPY_PHASE_STRIP = NO; - DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; - ENABLE_NS_ASSERTIONS = NO; - ENABLE_STRICT_OBJC_MSGSEND = YES; - GCC_C_LANGUAGE_STANDARD = gnu11; - GCC_NO_COMMON_BLOCKS = YES; - GCC_WARN_64_TO_32_BIT_CONVERSION = YES; - GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; - GCC_WARN_UNDECLARED_SELECTOR = YES; - GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; - GCC_WARN_UNUSED_FUNCTION = YES; - GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 16.0; - MTL_ENABLE_DEBUG_INFO = NO; - MTL_FAST_MATH = YES; - SDKROOT = iphoneos; - SWIFT_COMPILATION_MODE = wholemodule; - SWIFT_OPTIMIZATION_LEVEL = "-O"; - VALIDATE_PRODUCT = YES; - }; - name = Release; - }; - 37FD7E142910094500853C23 /* Debug */ = { - isa = XCBuildConfiguration; - buildSettings = { - ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; - ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; - CLANG_CXX_LANGUAGE_STANDARD = "c++14"; - CLANG_ENABLE_MODULES = YES; - CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 1; - DEVELOPMENT_TEAM = LXGRKDMEQU; - GCC_C_LANGUAGE_STANDARD = gnu11; - GENERATE_INFOPLIST_FILE = YES; - HEADER_SEARCH_PATHS = ( - ../, - "../fc_base/openfst-src/src/include", - "../fc_base/gflags-build/include", - "../fc_base/glog-build", - "../fc_base/glog-src/src", - ../kaldi, - ../build/Pods/LibTorch/install/include, - ); - INFOPLIST_FILE = WenetDemo/Info.plist; - INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES; - INFOPLIST_KEY_UILaunchStoryboardName = LaunchScreen; - INFOPLIST_KEY_UIMainStoryboardFile = Main; - INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; - INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; - IPHONEOS_DEPLOYMENT_TARGET = 14.6; - LD_RUNPATH_SEARCH_PATHS = ( - "$(inherited)", - "@executable_path/Frameworks", - ); - LIBRARY_SEARCH_PATHS = ( - "../build/decoder/Debug-iphoneos", - ../build/Pods/LibTorch/install/lib, - "../fc_base/openfst-build/src/lib/Debug-iphoneos", - "../fc_base/gflags-build/Debug-iphoneos", - "../fc_base/glog-build/Debug-iphoneos", - "../build/kaldi/Debug-iphoneos", - "../build/post_processor/Debug-iphoneos", - "../build/utils/Debug-iphoneos", - "../build/frontend/Debug-iphoneos", - ); - MARKETING_VERSION = 1.0; - OTHER_LDFLAGS = ( - "-ObjC", - "-l\"XNNPACK\"", - "-l\"c++\"", - "-l\"c10\"", - "-l\"clog\"", - "-l\"cpuinfo\"", - "-l\"eigen_blas\"", - "-l\"pthreadpool\"", - "-l\"pytorch_qnnpack\"", - "-l\"stdc++\"", - "-l\"torch\"", - "-l\"torch_cpu\"", - "-force_load", - ../build/Pods/LibTorch/install/lib/libtorch.a, - "-force_load", - ../build/Pods/LibTorch/install/lib/libtorch_cpu.a, - "-l\"gflags_nothreads_debug\"", - "-l\"glogd\"", - ); - PRODUCT_BUNDLE_IDENTIFIER = com.wenet.WenetDemo; - PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_EMIT_LOC_STRINGS = YES; - SWIFT_OBJC_BRIDGING_HEADER = "WenetDemo/wenet/WenetDemo-Bridging-Header.h"; - SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - SWIFT_VERSION = 5.0; - TARGETED_DEVICE_FAMILY = "1,2"; - }; - name = Debug; - }; - 37FD7E152910094500853C23 /* Release */ = { - isa = XCBuildConfiguration; - buildSettings = { - ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; - ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; - CLANG_CXX_LANGUAGE_STANDARD = "c++14"; - CLANG_ENABLE_MODULES = YES; - CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 1; - DEVELOPMENT_TEAM = LXGRKDMEQU; - GCC_C_LANGUAGE_STANDARD = gnu11; - GENERATE_INFOPLIST_FILE = YES; - HEADER_SEARCH_PATHS = ( - ../, - "../fc_base/openfst-src/src/include", - "../fc_base/gflags-build/include", - "../fc_base/glog-build", - "../fc_base/glog-src/src", - ../kaldi, - ../build/Pods/LibTorch/install/include, - ); - INFOPLIST_FILE = WenetDemo/Info.plist; - INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES; - INFOPLIST_KEY_UILaunchStoryboardName = LaunchScreen; - INFOPLIST_KEY_UIMainStoryboardFile = Main; - INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; - INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; - IPHONEOS_DEPLOYMENT_TARGET = 14.6; - LD_RUNPATH_SEARCH_PATHS = ( - "$(inherited)", - "@executable_path/Frameworks", - ); - LIBRARY_SEARCH_PATHS = ( - "../build/decoder/Release-iphoneos", - ../build/Pods/LibTorch/install/lib, - "../fc_base/openfst-build/src/lib/Release-iphoneos", - "../fc_base/gflags-build/Release-iphoneos", - "../fc_base/glog-build/Release-iphoneos", - "../build/kaldi/Release-iphoneos", - "../build/post_processor/Release-iphoneos", - "../build/utils/Release-iphoneos", - "../build/frontend/Release-iphoneos", - ); - MARKETING_VERSION = 1.0; - OTHER_LDFLAGS = ( - "-ObjC", - "-l\"XNNPACK\"", - "-l\"c++\"", - "-l\"c10\"", - "-l\"clog\"", - "-l\"cpuinfo\"", - "-l\"eigen_blas\"", - "-l\"pthreadpool\"", - "-l\"pytorch_qnnpack\"", - "-l\"stdc++\"", - "-l\"torch\"", - "-l\"torch_cpu\"", - "-force_load", - ../build/Pods/LibTorch/install/lib/libtorch.a, - "-force_load", - ../build/Pods/LibTorch/install/lib/libtorch_cpu.a, - "-l\"gflags_nothreads\"", - "-l\"glog\"", - ); - PRODUCT_BUNDLE_IDENTIFIER = com.wenet.WenetDemo; - PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_EMIT_LOC_STRINGS = YES; - SWIFT_OBJC_BRIDGING_HEADER = "WenetDemo/wenet/WenetDemo-Bridging-Header.h"; - SWIFT_VERSION = 5.0; - TARGETED_DEVICE_FAMILY = "1,2"; - }; - name = Release; - }; + 37FD7E112910094500853C23 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++20"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_ENABLE_OBJC_WEAK = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = dwarf; + ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_TESTABILITY = YES; + GCC_C_LANGUAGE_STANDARD = gnu11; + GCC_DYNAMIC_NO_PIC = NO; + GCC_NO_COMMON_BLOCKS = YES; + GCC_OPTIMIZATION_LEVEL = 0; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 16.0; + MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; + MTL_FAST_MATH = YES; + ONLY_ACTIVE_ARCH = YES; + SDKROOT = iphoneos; + SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + }; + name = Debug; + }; + 37FD7E122910094500853C23 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++20"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_ENABLE_OBJC_WEAK = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + ENABLE_NS_ASSERTIONS = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; + GCC_C_LANGUAGE_STANDARD = gnu11; + GCC_NO_COMMON_BLOCKS = YES; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 16.0; + MTL_ENABLE_DEBUG_INFO = NO; + MTL_FAST_MATH = YES; + SDKROOT = iphoneos; + SWIFT_COMPILATION_MODE = wholemodule; + SWIFT_OPTIMIZATION_LEVEL = "-O"; + VALIDATE_PRODUCT = YES; + }; + name = Release; + }; + 37FD7E142910094500853C23 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; + CLANG_CXX_LANGUAGE_STANDARD = "c++14"; + CLANG_ENABLE_MODULES = YES; + CODE_SIGN_STYLE = Automatic; + CURRENT_PROJECT_VERSION = 1; + DEVELOPMENT_TEAM = LXGRKDMEQU; + GCC_C_LANGUAGE_STANDARD = gnu11; + GENERATE_INFOPLIST_FILE = YES; + HEADER_SEARCH_PATHS = ( + ../, + "../fc_base/openfst-src/src/include", + "../fc_base/gflags-build/include", + "../fc_base/glog-build", + "../fc_base/glog-src/src", + ../kaldi, + ../build/Pods/LibTorch/install/include, + ); + INFOPLIST_FILE = WenetDemo/Info.plist; + INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES; + INFOPLIST_KEY_UILaunchStoryboardName = LaunchScreen; + INFOPLIST_KEY_UIMainStoryboardFile = Main; + INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; + INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; + IPHONEOS_DEPLOYMENT_TARGET = 14.6; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + ); + LIBRARY_SEARCH_PATHS = ( + "../build/decoder/Debug-iphoneos", + ../build/Pods/LibTorch/install/lib, + "../fc_base/openfst-build/src/lib/Debug-iphoneos", + "../fc_base/gflags-build/Debug-iphoneos", + "../fc_base/glog-build/Debug-iphoneos", + "../build/kaldi/Debug-iphoneos", + "../build/post_processor/Debug-iphoneos", + "../build/utils/Debug-iphoneos", + "../build/frontend/Debug-iphoneos", + ); + MARKETING_VERSION = 1.0; + OTHER_LDFLAGS = ( + "-ObjC", + "-l\"XNNPACK\"", + "-l\"c++\"", + "-l\"c10\"", + "-l\"clog\"", + "-l\"cpuinfo\"", + "-l\"eigen_blas\"", + "-l\"pthreadpool\"", + "-l\"pytorch_qnnpack\"", + "-l\"stdc++\"", + "-l\"torch\"", + "-l\"torch_cpu\"", + "-force_load", + ../build/Pods/LibTorch/install/lib/libtorch.a, + "-force_load", + ../build/Pods/LibTorch/install/lib/libtorch_cpu.a, + "-l\"gflags_nothreads_debug\"", + "-l\"glogd\"", + ); + PRODUCT_BUNDLE_IDENTIFIER = com.wenet.WenetDemo; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_EMIT_LOC_STRINGS = YES; + SWIFT_OBJC_BRIDGING_HEADER = "WenetDemo/wenet/WenetDemo-Bridging-Header.h"; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + SWIFT_VERSION = 5.0; + TARGETED_DEVICE_FAMILY = "1,2"; + }; + name = Debug; + }; + 37FD7E152910094500853C23 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; + CLANG_CXX_LANGUAGE_STANDARD = "c++14"; + CLANG_ENABLE_MODULES = YES; + CODE_SIGN_STYLE = Automatic; + CURRENT_PROJECT_VERSION = 1; + DEVELOPMENT_TEAM = LXGRKDMEQU; + GCC_C_LANGUAGE_STANDARD = gnu11; + GENERATE_INFOPLIST_FILE = YES; + HEADER_SEARCH_PATHS = ( + ../, + "../fc_base/openfst-src/src/include", + "../fc_base/gflags-build/include", + "../fc_base/glog-build", + "../fc_base/glog-src/src", + ../kaldi, + ../build/Pods/LibTorch/install/include, + ); + INFOPLIST_FILE = WenetDemo/Info.plist; + INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES; + INFOPLIST_KEY_UILaunchStoryboardName = LaunchScreen; + INFOPLIST_KEY_UIMainStoryboardFile = Main; + INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; + INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; + IPHONEOS_DEPLOYMENT_TARGET = 14.6; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + ); + LIBRARY_SEARCH_PATHS = ( + "../build/decoder/Release-iphoneos", + ../build/Pods/LibTorch/install/lib, + "../fc_base/openfst-build/src/lib/Release-iphoneos", + "../fc_base/gflags-build/Release-iphoneos", + "../fc_base/glog-build/Release-iphoneos", + "../build/kaldi/Release-iphoneos", + "../build/post_processor/Release-iphoneos", + "../build/utils/Release-iphoneos", + "../build/frontend/Release-iphoneos", + ); + MARKETING_VERSION = 1.0; + OTHER_LDFLAGS = ( + "-ObjC", + "-l\"XNNPACK\"", + "-l\"c++\"", + "-l\"c10\"", + "-l\"clog\"", + "-l\"cpuinfo\"", + "-l\"eigen_blas\"", + "-l\"pthreadpool\"", + "-l\"pytorch_qnnpack\"", + "-l\"stdc++\"", + "-l\"torch\"", + "-l\"torch_cpu\"", + "-force_load", + ../build/Pods/LibTorch/install/lib/libtorch.a, + "-force_load", + ../build/Pods/LibTorch/install/lib/libtorch_cpu.a, + "-l\"gflags_nothreads\"", + "-l\"glog\"", + ); + PRODUCT_BUNDLE_IDENTIFIER = com.wenet.WenetDemo; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_EMIT_LOC_STRINGS = YES; + SWIFT_OBJC_BRIDGING_HEADER = "WenetDemo/wenet/WenetDemo-Bridging-Header.h"; + SWIFT_VERSION = 5.0; + TARGETED_DEVICE_FAMILY = "1,2"; + }; + name = Release; + }; /* End XCBuildConfiguration section */ /* Begin XCConfigurationList section */ - 37FD7DFA2910094300853C23 /* Build configuration list for PBXProject "WenetDemo" */ = { - isa = XCConfigurationList; - buildConfigurations = ( - 37FD7E112910094500853C23 /* Debug */, - 37FD7E122910094500853C23 /* Release */, - ); - defaultConfigurationIsVisible = 0; - defaultConfigurationName = Release; - }; - 37FD7E132910094500853C23 /* Build configuration list for PBXNativeTarget "WenetDemo" */ = { - isa = XCConfigurationList; - buildConfigurations = ( - 37FD7E142910094500853C23 /* Debug */, - 37FD7E152910094500853C23 /* Release */, - ); - defaultConfigurationIsVisible = 0; - defaultConfigurationName = Release; - }; + 37FD7DFA2910094300853C23 /* Build configuration list for PBXProject "WenetDemo" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 37FD7E112910094500853C23 /* Debug */, + 37FD7E122910094500853C23 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 37FD7E132910094500853C23 /* Build configuration list for PBXNativeTarget "WenetDemo" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 37FD7E142910094500853C23 /* Debug */, + 37FD7E152910094500853C23 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; /* End XCConfigurationList section */ - }; - rootObject = 37FD7DF72910094300853C23 /* Project object */; + }; + rootObject = 37FD7DF72910094300853C23 /* Project object */; } diff --git a/runtime/ios/WenetDemo/WenetDemo.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/runtime/ios/WenetDemo/WenetDemo.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist index 18d981003d..3d4c1e5525 100644 --- a/runtime/ios/WenetDemo/WenetDemo.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +++ b/runtime/ios/WenetDemo/WenetDemo.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -2,7 +2,7 @@ - IDEDidComputeMac32BitWarning - + IDEDidComputeMac32BitWarning + diff --git a/runtime/ios/WenetDemo/WenetDemo/Info.plist b/runtime/ios/WenetDemo/WenetDemo/Info.plist index b2039f5877..16ad1537f3 100644 --- a/runtime/ios/WenetDemo/WenetDemo/Info.plist +++ b/runtime/ios/WenetDemo/WenetDemo/Info.plist @@ -2,25 +2,25 @@ - UIApplicationSceneManifest - - UIApplicationSupportsMultipleScenes - - UISceneConfigurations - - UIWindowSceneSessionRoleApplication - - - UISceneConfigurationName - Default Configuration - UISceneDelegateClassName - $(PRODUCT_MODULE_NAME).SceneDelegate - UISceneStoryboardFile - Main - - - - + UIApplicationSceneManifest + + UIApplicationSupportsMultipleScenes + + UISceneConfigurations + + UIWindowSceneSessionRoleApplication + + + UISceneConfigurationName + Default Configuration + UISceneDelegateClassName + $(PRODUCT_MODULE_NAME).SceneDelegate + UISceneStoryboardFile + Main + + + + NSMicrophoneUsageDescription Need microphone access for recording speech From 616b4b2df6baa73ccc11b7f9ae9586c4ded39013 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=A9=AC=E4=B8=B9?= Date: Thu, 10 Nov 2022 23:22:38 +0800 Subject: [PATCH 06/13] Fix lint trailing whitespace --- runtime/core/toolchains/ios.toolchain.cmake | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/runtime/core/toolchains/ios.toolchain.cmake b/runtime/core/toolchains/ios.toolchain.cmake index 5c8add8c59..2bcb0adf7b 100644 --- a/runtime/core/toolchains/ios.toolchain.cmake +++ b/runtime/core/toolchains/ios.toolchain.cmake @@ -296,7 +296,7 @@ if(PLATFORM_INT STREQUAL "OS") set(ARCHS armv7 armv7s arm64) set(APPLE_TARGET_TRIPLE_INT arm-apple-ios${DEPLOYMENT_TARGET}) else() - set(APPLE_TARGET_TRIPLE_INT ${ARCHS_SPLIT}-apple-ios${DEPLOYMENT_TARGET}) + set(APPLE_TARGET_TRIPLE_INT ${ARCHS_SPLIT}-apple-ios${DEPLOYMENT_TARGET}) endif() elseif(PLATFORM_INT STREQUAL "OS64") set(SDK_NAME iphoneos) @@ -920,7 +920,7 @@ set(CMAKE_TRY_COMPILE_PLATFORM_VARIABLES ) if(NAMED_LANGUAGE_SUPPORT_INT) - list(APPEND CMAKE_TRY_COMPILE_PLATFORM_VARIABLES + list(APPEND CMAKE_TRY_COMPILE_PLATFORM_VARIABLES CMAKE_OBJC_FLAGS CMAKE_OBJC_DEBUG CMAKE_OBJC_MINSIZEREL @@ -956,7 +956,7 @@ endif() set(CMAKE_FIND_FRAMEWORK FIRST) # Set up the default search directories for frameworks. -if(PLATFORM_INT MATCHES "^MAC_CATALYST") +if(PLATFORM_INT MATCHES "^MAC_CATALYST") set(CMAKE_FRAMEWORK_PATH ${CMAKE_DEVELOPER_ROOT}/Library/PrivateFrameworks ${CMAKE_OSX_SYSROOT_INT}/System/Library/Frameworks From 16ef941c292c0666de51745cc9052fd5b90f2e96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=A9=AC=E4=B8=B9?= Date: Thu, 10 Nov 2022 23:49:58 +0800 Subject: [PATCH 07/13] Simplify build and fix some cpplint --- runtime/ios/CMakeLists.txt | 6 ------ runtime/ios/README.md | 14 +++----------- .../WenetDemo/wenet/WenetDemo-Bridging-Header.h | 7 ++++++- runtime/ios/WenetDemo/WenetDemo/wenet/wenet.h | 6 +++--- 4 files changed, 12 insertions(+), 21 deletions(-) diff --git a/runtime/ios/CMakeLists.txt b/runtime/ios/CMakeLists.txt index 567ee97834..3fd20cd624 100644 --- a/runtime/ios/CMakeLists.txt +++ b/runtime/ios/CMakeLists.txt @@ -52,12 +52,6 @@ add_subdirectory(post_processor) add_subdirectory(kaldi) # kaldi: wfst based decoder add_subdirectory(decoder) -# Optionally, you can build with gRPC -if(GRPC) - include(grpc) - add_subdirectory(grpc) -endif() - # Unit Test if(BUILD_TESTING) include(gtest) diff --git a/runtime/ios/README.md b/runtime/ios/README.md index dec19a606e..dee06c1106 100644 --- a/runtime/ios/README.md +++ b/runtime/ios/README.md @@ -2,21 +2,13 @@ ## Build application from source code -### 1) Generate cmake project and install LibTorch pod +### 1) Generate cmake project, install LibTorch pod and build static libraries ``` cd runtime/ios/build -cmake .. -G Xcode -DTORCH=OFF -DONNX=OFF -DIOS=ON -DGRAPH_TOOLS=ON -DBUILD_TESTING=OFF -DCMAKE_TOOLCHAIN_FILE=../toolchains/ios.toolchain.cmake -DPLATFORM=OS64 -DENABLE_BITCODE=FALSE +cmake .. -G Xcode -DTORCH=OFF -DONNX=OFF -DIOS=ON -DGRAPH_TOOLS=OFF -DBUILD_TESTING=OFF -DCMAKE_TOOLCHAIN_FILE=../toolchains/ios.toolchain.cmake -DPLATFORM=OS64 -DENABLE_BITCODE=FALSE pod install -``` - -### 2) Remove executable targets in wenet project - -Open wenet.xcodeproj in runtime/ios/build folder with Xcode, remove all 6 executable targets, leave static library targets only, close Xcode to save workspace. -### 3) Build static libraries - -``` # Build debug version cmake --build . --config Debug @@ -24,7 +16,7 @@ cmake --build . --config Debug cmake --build . --config Release ``` -### 4) Build and run iOS application +### 2) Build and run iOS application You can use our pretrained model (click the following link to download): diff --git a/runtime/ios/WenetDemo/WenetDemo/wenet/WenetDemo-Bridging-Header.h b/runtime/ios/WenetDemo/WenetDemo/wenet/WenetDemo-Bridging-Header.h index fe205e4b22..47cb181889 100644 --- a/runtime/ios/WenetDemo/WenetDemo/wenet/WenetDemo-Bridging-Header.h +++ b/runtime/ios/WenetDemo/WenetDemo/wenet/WenetDemo-Bridging-Header.h @@ -1,6 +1,7 @@ // Copyright (c) 2022 Dan Ma (1067837450@qq.com) // -// Use this file to import your target's public headers that you would like to expose to Swift. +// Use this file to import your target's public headers +// that you would like to expose to Swift. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -14,4 +15,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +#ifndef RUNTIME_IOS_WENETDEMO_WENETDEMO_WENET_WENETDEMO_BRIDGING_HEADER_H_ +#define RUNTIME_IOS_WENETDEMO_WENETDEMO_WENET_WENETDEMO_BRIDGING_HEADER_H_ #import "wenet.h" + +#endif //RUNTIME_IOS_WENETDEMO_WENETDEMO_WENET_WENETDEMO_BRIDGING_HEADER_H_ \ No newline at end of file diff --git a/runtime/ios/WenetDemo/WenetDemo/wenet/wenet.h b/runtime/ios/WenetDemo/WenetDemo/wenet/wenet.h index cca7391784..1b1b22d0f6 100644 --- a/runtime/ios/WenetDemo/WenetDemo/wenet/wenet.h +++ b/runtime/ios/WenetDemo/WenetDemo/wenet/wenet.h @@ -15,8 +15,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -#ifndef wenet_h -#define wenet_h +#ifndef RUNTIME_IOS_WENETDEMO_WENETDEMO_WENET_WENET_H_ +#define RUNTIME_IOS_WENETDEMO_WENETDEMO_WENET_WENET_H_ #include @@ -36,4 +36,4 @@ @end -#endif /* wenet_h */ +#endif // RUNTIME_IOS_WENETDEMO_WENETDEMO_WENET_WENET_H_ From 88d0d22b7dc62bd190191284feb60ebd1c14524c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=A9=AC=E4=B8=B9?= Date: Fri, 11 Nov 2022 00:25:48 +0800 Subject: [PATCH 08/13] Fix some cpplint --- .../ios/WenetDemo/WenetDemo/wenet/WenetDemo-Bridging-Header.h | 3 ++- runtime/ios/WenetDemo/WenetDemo/wenet/wenet.h | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/runtime/ios/WenetDemo/WenetDemo/wenet/WenetDemo-Bridging-Header.h b/runtime/ios/WenetDemo/WenetDemo/wenet/WenetDemo-Bridging-Header.h index 47cb181889..5cec9898b6 100644 --- a/runtime/ios/WenetDemo/WenetDemo/wenet/WenetDemo-Bridging-Header.h +++ b/runtime/ios/WenetDemo/WenetDemo/wenet/WenetDemo-Bridging-Header.h @@ -17,6 +17,7 @@ #ifndef RUNTIME_IOS_WENETDEMO_WENETDEMO_WENET_WENETDEMO_BRIDGING_HEADER_H_ #define RUNTIME_IOS_WENETDEMO_WENETDEMO_WENET_WENETDEMO_BRIDGING_HEADER_H_ + #import "wenet.h" -#endif //RUNTIME_IOS_WENETDEMO_WENETDEMO_WENET_WENETDEMO_BRIDGING_HEADER_H_ \ No newline at end of file +#endif // RUNTIME_IOS_WENETDEMO_WENETDEMO_WENET_WENETDEMO_BRIDGING_HEADER_H_ diff --git a/runtime/ios/WenetDemo/WenetDemo/wenet/wenet.h b/runtime/ios/WenetDemo/WenetDemo/wenet/wenet.h index 1b1b22d0f6..7dee7c3ec0 100644 --- a/runtime/ios/WenetDemo/WenetDemo/wenet/wenet.h +++ b/runtime/ios/WenetDemo/WenetDemo/wenet/wenet.h @@ -36,4 +36,4 @@ @end -#endif // RUNTIME_IOS_WENETDEMO_WENETDEMO_WENET_WENET_H_ +#endif // RUNTIME_IOS_WENETDEMO_WENETDEMO_WENET_WENET_H_ From a484dee133a7b0dfd5e69bd5519b1c97bf8f84dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=A9=AC=E4=B8=B9?= Date: Fri, 11 Nov 2022 22:50:19 +0800 Subject: [PATCH 09/13] Add NOLINT to Objective C header file --- runtime/ios/WenetDemo/WenetDemo/wenet/wenet.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/runtime/ios/WenetDemo/WenetDemo/wenet/wenet.h b/runtime/ios/WenetDemo/WenetDemo/wenet/wenet.h index 7dee7c3ec0..676fabcca6 100644 --- a/runtime/ios/WenetDemo/WenetDemo/wenet/wenet.h +++ b/runtime/ios/WenetDemo/WenetDemo/wenet/wenet.h @@ -24,15 +24,15 @@ @interface Wenet : NSObject -- (nullable instancetype)initWithModelPath:(NSString*)modelPath DictPath:(NSString*)dictPath; +- (nullable instancetype)initWithModelPath:(NSString*)modelPath DictPath:(NSString*)dictPath; // NOLINT - (void)reset; -- (void)acceptWaveForm: (float*)pcm: (int)size; +- (void)acceptWaveForm: (float*)pcm: (int)size; // NOLINT - (void)decode; -- (NSString*)get_result; +- (NSString*)get_result; // NOLINT @end From 53ee67661b2cefe55b10a4ab1ffb11ce524d7617 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=A9=AC=E4=B8=B9?= Date: Sat, 12 Nov 2022 09:21:35 +0800 Subject: [PATCH 10/13] Merge ios_asr_model into torch_asr_model --- runtime/core/cmake/libtorch.cmake | 24 +- runtime/core/decoder/CMakeLists.txt | 5 +- runtime/core/decoder/ios_asr_model.cc | 233 ------------------ runtime/core/decoder/ios_asr_model.h | 63 ----- runtime/core/decoder/torch_asr_model.cc | 4 + runtime/core/decoder/torch_asr_model.h | 4 + runtime/ios/README.md | 2 +- .../ios/WenetDemo/WenetDemo/wenet/wenet.mm | 6 +- 8 files changed, 31 insertions(+), 310 deletions(-) delete mode 100644 runtime/core/decoder/ios_asr_model.cc delete mode 100644 runtime/core/decoder/ios_asr_model.h diff --git a/runtime/core/cmake/libtorch.cmake b/runtime/core/cmake/libtorch.cmake index 40a64ff84f..e6716a68a6 100644 --- a/runtime/core/cmake/libtorch.cmake +++ b/runtime/core/cmake/libtorch.cmake @@ -5,6 +5,9 @@ if(TORCH) add_definitions(-DUSE_GPU) set(CUDA_NAME "cu113") endif() + if(IOS) + add_definitions(-DIOS) + endif() if(${CMAKE_SYSTEM_NAME} STREQUAL "Windows") if(GPU) message(FATAL_ERROR "GPU on Windows is unsupported, you can use CPU version") @@ -40,17 +43,24 @@ if(TORCH) endif() set(LIBTORCH_URL "https://download.pytorch.org/libtorch/cpu/libtorch-macos-${PYTORCH_VERSION}.zip") set(URL_HASH "SHA256=07cac2c36c34f13065cb9559ad5270109ecbb468252fb0aeccfd89322322a2b5") + elseif(${CMAKE_SYSTEM_NAME} STREQUAL "iOS") + if(GPU) + message(FATAL_ERROR "GPU on iOS is unsupported, you can use CPU version") + endif() else() message(FATAL_ERROR "Unsupported CMake System Name '${CMAKE_SYSTEM_NAME}' (expected 'Windows', 'Linux' or 'Darwin')") endif() - FetchContent_Declare(libtorch - URL ${LIBTORCH_URL} - URL_HASH ${URL_HASH} - ) - FetchContent_MakeAvailable(libtorch) - find_package(Torch REQUIRED PATHS ${libtorch_SOURCE_DIR} NO_DEFAULT_PATH) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${TORCH_CXX_FLAGS} -DC10_USE_GLOG") + # iOS use LibTorch from pod install + if(NOT IOS) + FetchContent_Declare(libtorch + URL ${LIBTORCH_URL} + URL_HASH ${URL_HASH} + ) + FetchContent_MakeAvailable(libtorch) + find_package(Torch REQUIRED PATHS ${libtorch_SOURCE_DIR} NO_DEFAULT_PATH) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${TORCH_CXX_FLAGS} -DC10_USE_GLOG") + endif() if(MSVC) file(GLOB TORCH_DLLS "${TORCH_INSTALL_PREFIX}/lib/*.dll") diff --git a/runtime/core/decoder/CMakeLists.txt b/runtime/core/decoder/CMakeLists.txt index d6924b81c8..49503a2208 100644 --- a/runtime/core/decoder/CMakeLists.txt +++ b/runtime/core/decoder/CMakeLists.txt @@ -10,15 +10,12 @@ set(decoder_srcs if(NOT TORCH AND NOT ONNX AND NOT XPU AND NOT IOS) message(FATAL_ERROR "Please build with TORCH or ONNX or XPU or IOS!!!") endif() -if(TORCH) +if(TORCH OR IOS) list(APPEND decoder_srcs torch_asr_model.cc) endif() if(ONNX) list(APPEND decoder_srcs onnx_asr_model.cc) endif() -if(IOS) - list(APPEND decoder_srcs ios_asr_model.cc) -endif() add_library(decoder STATIC ${decoder_srcs}) target_link_libraries(decoder PUBLIC kaldi-decoder frontend diff --git a/runtime/core/decoder/ios_asr_model.cc b/runtime/core/decoder/ios_asr_model.cc deleted file mode 100644 index c88a0a6646..0000000000 --- a/runtime/core/decoder/ios_asr_model.cc +++ /dev/null @@ -1,233 +0,0 @@ -// Copyright (c) 2020 Mobvoi Inc (Binbin Zhang, Di Wu) -// 2022 Binbin Zhang (binbzha@qq.com) -// 2022 Dan Ma (1067837450@qq.com) -// -// 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. - - -#include "decoder/ios_asr_model.h" - -#include -#include -#include -#include - -#include "torch/script.h" - -namespace wenet { - -void IosAsrModel::Read(const std::string& model_path) { - torch::DeviceType device = at::kCPU; - torch::jit::script::Module model = torch::jit::load(model_path, device); - model_ = std::make_shared(std::move(model)); - torch::NoGradGuard no_grad; - model_->eval(); - torch::jit::IValue o1 = model_->run_method("subsampling_rate"); - CHECK_EQ(o1.isInt(), true); - subsampling_rate_ = o1.toInt(); - torch::jit::IValue o2 = model_->run_method("right_context"); - CHECK_EQ(o2.isInt(), true); - right_context_ = o2.toInt(); - torch::jit::IValue o3 = model_->run_method("sos_symbol"); - CHECK_EQ(o3.isInt(), true); - sos_ = o3.toInt(); - torch::jit::IValue o4 = model_->run_method("eos_symbol"); - CHECK_EQ(o4.isInt(), true); - eos_ = o4.toInt(); - torch::jit::IValue o5 = model_->run_method("is_bidirectional_decoder"); - CHECK_EQ(o5.isBool(), true); - is_bidirectional_decoder_ = o5.toBool(); - - VLOG(1) << "Torch Model Info:"; - VLOG(1) << "\tsubsampling_rate " << subsampling_rate_; - VLOG(1) << "\tright context " << right_context_; - VLOG(1) << "\tsos " << sos_; - VLOG(1) << "\teos " << eos_; - VLOG(1) << "\tis bidirectional decoder " << is_bidirectional_decoder_; -} - -IosAsrModel::IosAsrModel(const IosAsrModel& other) { - // 1. Init the model info - right_context_ = other.right_context_; - subsampling_rate_ = other.subsampling_rate_; - sos_ = other.sos_; - eos_ = other.eos_; - is_bidirectional_decoder_ = other.is_bidirectional_decoder_; - chunk_size_ = other.chunk_size_; - num_left_chunks_ = other.num_left_chunks_; - offset_ = other.offset_; - // 2. Model copy, just copy the model ptr since: - // PyTorch allows using multiple CPU threads during TorchScript model - // inference, please see https://pytorch.org/docs/stable/notes/cpu_ - // threading_torchscript_inference.html - model_ = other.model_; - - // NOTE(Binbin Zhang): - // inner states for forward are not copied here. -} - -std::shared_ptr IosAsrModel::Copy() const { - auto asr_model = std::make_shared(*this); - // Reset the inner states for new decoding - asr_model->Reset(); - return asr_model; -} - -void IosAsrModel::Reset() { - offset_ = 0; - att_cache_ = std::move(torch::zeros({0, 0, 0, 0})); - cnn_cache_ = std::move(torch::zeros({0, 0, 0, 0})); - encoder_outs_.clear(); - cached_feature_.clear(); -} - -void IosAsrModel::ForwardEncoderFunc( - const std::vector>& chunk_feats, - std::vector>* out_prob) { - // 1. Prepare libtorch required data, splice cached_feature_ and chunk_feats - // The first dimension is for batchsize, which is 1. - int num_frames = cached_feature_.size() + chunk_feats.size(); - const int feature_dim = chunk_feats[0].size(); - torch::Tensor feats = - torch::zeros({1, num_frames, feature_dim}, torch::kFloat); - for (size_t i = 0; i < cached_feature_.size(); ++i) { - torch::Tensor row = - torch::from_blob(const_cast(cached_feature_[i].data()), - {feature_dim}, torch::kFloat) - .clone(); - feats[0][i] = std::move(row); - } - for (size_t i = 0; i < chunk_feats.size(); ++i) { - torch::Tensor row = - torch::from_blob(const_cast(chunk_feats[i].data()), - {feature_dim}, torch::kFloat) - .clone(); - feats[0][cached_feature_.size() + i] = std::move(row); - } - - // 2. Encoder chunk forward - int required_cache_size = chunk_size_ * num_left_chunks_; - torch::NoGradGuard no_grad; - std::vector inputs = {feats, offset_, required_cache_size, - att_cache_, cnn_cache_}; - - // Refer interfaces in wenet/transformer/asr_model.py - auto outputs = - model_->get_method("forward_encoder_chunk")(inputs).toTuple()->elements(); - CHECK_EQ(outputs.size(), 3); - torch::Tensor chunk_out = outputs[0].toTensor(); - att_cache_ = outputs[1].toTensor(); - cnn_cache_ = outputs[2].toTensor(); - offset_ += chunk_out.size(1); - - // The first dimension of returned value is for batchsize, which is 1 - torch::Tensor ctc_log_probs = - model_->run_method("ctc_activation", chunk_out).toTensor()[0]; - encoder_outs_.push_back(std::move(chunk_out)); - - // Copy to output - int num_outputs = ctc_log_probs.size(0); - int output_dim = ctc_log_probs.size(1); - out_prob->resize(num_outputs); - for (int i = 0; i < num_outputs; i++) { - (*out_prob)[i].resize(output_dim); - memcpy((*out_prob)[i].data(), ctc_log_probs[i].data_ptr(), - sizeof(float) * output_dim); - } -} - -float IosAsrModel::ComputeAttentionScore(const torch::Tensor& prob, - const std::vector& hyp, - int eos) { - float score = 0.0f; - auto accessor = prob.accessor(); - for (size_t j = 0; j < hyp.size(); ++j) { - score += accessor[j][hyp[j]]; - } - score += accessor[hyp.size()][eos]; - return score; -} - -void IosAsrModel::AttentionRescoring( - const std::vector>& hyps, float reverse_weight, - std::vector* rescoring_score) { - CHECK(rescoring_score != nullptr); - int num_hyps = hyps.size(); - rescoring_score->resize(num_hyps, 0.0f); - - if (num_hyps == 0) { - return; - } - // No encoder output - if (encoder_outs_.size() == 0) { - return; - } - - torch::NoGradGuard no_grad; - // Step 1: Prepare input for libtorch - torch::Tensor hyps_length = torch::zeros({num_hyps}, torch::kLong); - int max_hyps_len = 0; - for (size_t i = 0; i < num_hyps; ++i) { - int length = hyps[i].size() + 1; - max_hyps_len = std::max(length, max_hyps_len); - hyps_length[i] = static_cast(length); - } - torch::Tensor hyps_tensor = - torch::zeros({num_hyps, max_hyps_len}, torch::kLong); - for (size_t i = 0; i < num_hyps; ++i) { - const std::vector& hyp = hyps[i]; - hyps_tensor[i][0] = sos_; - for (size_t j = 0; j < hyp.size(); ++j) { - hyps_tensor[i][j + 1] = hyp[j]; - } - } - - // Step 2: Forward attention decoder by hyps and corresponding encoder_outs_ - torch::Tensor encoder_out = torch::cat(encoder_outs_, 1); - auto outputs = model_ - ->run_method("forward_attention_decoder", hyps_tensor, - hyps_length, encoder_out, reverse_weight) - .toTuple() - ->elements(); - - auto probs = outputs[0].toTensor(); - auto r_probs = outputs[1].toTensor(); - - CHECK_EQ(probs.size(0), num_hyps); - CHECK_EQ(probs.size(1), max_hyps_len); - - // Step 3: Compute rescoring score - for (size_t i = 0; i < num_hyps; ++i) { - const std::vector& hyp = hyps[i]; - float score = 0.0f; - // left-to-right decoder score - score = ComputeAttentionScore(probs[i], hyp, eos_); - // Optional: Used for right to left score - float r_score = 0.0f; - if (is_bidirectional_decoder_ && reverse_weight > 0) { - // right-to-left score - CHECK_EQ(r_probs.size(0), num_hyps); - CHECK_EQ(r_probs.size(1), max_hyps_len); - std::vector r_hyp(hyp.size()); - std::reverse_copy(hyp.begin(), hyp.end(), r_hyp.begin()); - // right to left decoder score - r_score = ComputeAttentionScore(r_probs[i], r_hyp, eos_); - } - - // combined left-to-right and right-to-left score - (*rescoring_score)[i] = - score * (1 - reverse_weight) + r_score * reverse_weight; - } -} - -} // namespace wenet diff --git a/runtime/core/decoder/ios_asr_model.h b/runtime/core/decoder/ios_asr_model.h deleted file mode 100644 index c55a538da5..0000000000 --- a/runtime/core/decoder/ios_asr_model.h +++ /dev/null @@ -1,63 +0,0 @@ -// Copyright (c) 2020 Mobvoi Inc (Binbin Zhang, Di Wu) -// 2022 Binbin Zhang (binbzha@qq.com) -// 2022 Dan Ma (1067837450@qq.com) -// -// 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. - - -#ifndef DECODER_IOS_ASR_MODEL_H_ -#define DECODER_IOS_ASR_MODEL_H_ - -#include -#include -#include - -#include "torch/script.h" - -#include "decoder/asr_model.h" -#include "utils/utils.h" - -namespace wenet { - -class IosAsrModel : public AsrModel { - public: - using TorchModule = torch::jit::script::Module; - IosAsrModel() = default; - IosAsrModel(const IosAsrModel& other); - void Read(const std::string& model_path); - std::shared_ptr torch_model() const { return model_; } - void Reset() override; - void AttentionRescoring(const std::vector>& hyps, - float reverse_weight, - std::vector* rescoring_score) override; - std::shared_ptr Copy() const override; - - protected: - void ForwardEncoderFunc(const std::vector>& chunk_feats, - std::vector>* ctc_prob) override; - - float ComputeAttentionScore(const torch::Tensor& prob, - const std::vector& hyp, int eos); - - private: - std::shared_ptr model_ = nullptr; - std::vector encoder_outs_; - // transformer/conformer attention cache - torch::Tensor att_cache_ = torch::zeros({0, 0, 0, 0}); - // conformer-only conv_module cache - torch::Tensor cnn_cache_ = torch::zeros({0, 0, 0, 0}); -}; - -} // namespace wenet - -#endif // DECODER_IOS_ASR_MODEL_H_ diff --git a/runtime/core/decoder/torch_asr_model.cc b/runtime/core/decoder/torch_asr_model.cc index 4775761ac5..f41c5cdafd 100644 --- a/runtime/core/decoder/torch_asr_model.cc +++ b/runtime/core/decoder/torch_asr_model.cc @@ -22,10 +22,13 @@ #include #include "torch/script.h" +#ifndef IOS #include "torch/torch.h" +#endif namespace wenet { +#ifndef IOS void TorchAsrModel::InitEngineThreads(int num_threads) { // For multi-thread performance at::set_num_threads(num_threads); @@ -36,6 +39,7 @@ void TorchAsrModel::InitEngineThreads(int num_threads) { VLOG(1) << "Num intra-op threads: " << at::get_num_threads(); VLOG(1) << "Num inter-op threads: " << at::get_num_interop_threads(); } +#endif void TorchAsrModel::Read(const std::string& model_path) { torch::DeviceType device = at::kCPU; diff --git a/runtime/core/decoder/torch_asr_model.h b/runtime/core/decoder/torch_asr_model.h index a29cc998a0..2a1f15c23f 100644 --- a/runtime/core/decoder/torch_asr_model.h +++ b/runtime/core/decoder/torch_asr_model.h @@ -22,7 +22,9 @@ #include #include "torch/script.h" +#ifndef IOS #include "torch/torch.h" +#endif #include "decoder/asr_model.h" #include "utils/utils.h" @@ -30,9 +32,11 @@ namespace wenet { class TorchAsrModel : public AsrModel { +#ifndef IOS public: // Note: Do not call the InitEngineThreads function more than once. static void InitEngineThreads(int num_threads = 1); +#endif public: using TorchModule = torch::jit::script::Module; diff --git a/runtime/ios/README.md b/runtime/ios/README.md index dee06c1106..1a9f091dee 100644 --- a/runtime/ios/README.md +++ b/runtime/ios/README.md @@ -6,7 +6,7 @@ ``` cd runtime/ios/build -cmake .. -G Xcode -DTORCH=OFF -DONNX=OFF -DIOS=ON -DGRAPH_TOOLS=OFF -DBUILD_TESTING=OFF -DCMAKE_TOOLCHAIN_FILE=../toolchains/ios.toolchain.cmake -DPLATFORM=OS64 -DENABLE_BITCODE=FALSE +cmake .. -G Xcode -DTORCH=ON -DONNX=OFF -DIOS=ON -DGRAPH_TOOLS=OFF -DBUILD_TESTING=OFF -DCMAKE_TOOLCHAIN_FILE=../toolchains/ios.toolchain.cmake -DPLATFORM=OS64 -DENABLE_BITCODE=FALSE pod install # Build debug version diff --git a/runtime/ios/WenetDemo/WenetDemo/wenet/wenet.mm b/runtime/ios/WenetDemo/WenetDemo/wenet/wenet.mm index cf1df11a58..6936f604f8 100644 --- a/runtime/ios/WenetDemo/WenetDemo/wenet/wenet.mm +++ b/runtime/ios/WenetDemo/WenetDemo/wenet/wenet.mm @@ -17,8 +17,10 @@ #include "wenet.h" +#define IOS + #include "decoder/asr_decoder.h" -#include "decoder/ios_asr_model.h" +#include "decoder/torch_asr_model.h" #include "frontend/feature_pipeline.h" #include "frontend/wav.h" #include "post_processor/post_processor.h" @@ -46,7 +48,7 @@ - (nullable instancetype)initWithModelPath:(NSString*)modelPath DictPath:(NSStri if (std::find(qengines.begin(), qengines.end(), at::QEngine::QNNPACK) != qengines.end()) { at::globalContext().setQEngine(at::QEngine::QNNPACK); } - auto model = std::make_shared(); + auto model = std::make_shared(); model->Read(modelPath.UTF8String); resource = std::make_shared(); resource->model = model; From 329d09acbf3df86a1f6cf1cdd51a8d4b1c43c9ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=A9=AC=E4=B8=B9?= Date: Sat, 12 Nov 2022 09:32:20 +0800 Subject: [PATCH 11/13] Fix lint --- runtime/core/decoder/torch_asr_model.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/runtime/core/decoder/torch_asr_model.h b/runtime/core/decoder/torch_asr_model.h index 2a1f15c23f..9722406014 100644 --- a/runtime/core/decoder/torch_asr_model.h +++ b/runtime/core/decoder/torch_asr_model.h @@ -32,8 +32,9 @@ namespace wenet { class TorchAsrModel : public AsrModel { -#ifndef IOS + public: +#ifndef IOS // Note: Do not call the InitEngineThreads function more than once. static void InitEngineThreads(int num_threads = 1); #endif From a6a2c17e5f68cd8c19413b643f3a58e0e0d7db74 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=A9=AC=E4=B8=B9?= Date: Sat, 12 Nov 2022 09:34:56 +0800 Subject: [PATCH 12/13] Fix lint --- runtime/core/decoder/torch_asr_model.h | 1 - 1 file changed, 1 deletion(-) diff --git a/runtime/core/decoder/torch_asr_model.h b/runtime/core/decoder/torch_asr_model.h index 9722406014..9c6e79a18b 100644 --- a/runtime/core/decoder/torch_asr_model.h +++ b/runtime/core/decoder/torch_asr_model.h @@ -32,7 +32,6 @@ namespace wenet { class TorchAsrModel : public AsrModel { - public: #ifndef IOS // Note: Do not call the InitEngineThreads function more than once. From 6afa21b28b22f51ac144cc36ddaa6a0d6b942d85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=A9=AC=E4=B8=B9?= Date: Sat, 12 Nov 2022 21:34:26 +0800 Subject: [PATCH 13/13] Fix code style --- .../WenetDemo.xcodeproj/project.pbxproj | 8 +- .../ios/WenetDemo/WenetDemo/AppDelegate.swift | 48 ++-- .../WenetDemo/WenetDemo/SceneDelegate.swift | 90 +++++--- .../WenetDemo/WenetDemo/ViewController.swift | 211 ++++++++++-------- runtime/ios/WenetDemo/WenetDemo/wenet/wenet.h | 3 +- .../ios/WenetDemo/WenetDemo/wenet/wenet.mm | 156 ++++++------- 6 files changed, 283 insertions(+), 233 deletions(-) diff --git a/runtime/ios/WenetDemo/WenetDemo.xcodeproj/project.pbxproj b/runtime/ios/WenetDemo/WenetDemo.xcodeproj/project.pbxproj index 9563d20b6c..f39d10f704 100644 --- a/runtime/ios/WenetDemo/WenetDemo.xcodeproj/project.pbxproj +++ b/runtime/ios/WenetDemo/WenetDemo.xcodeproj/project.pbxproj @@ -46,15 +46,15 @@ 37C64C972912B06800BFCE0B /* libutils.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libutils.a; path = "../build/utils/Debug-iphoneos/libutils.a"; sourceTree = ""; }; 37C64C992912B0A000BFCE0B /* libfrontend.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libfrontend.a; path = "../build/frontend/Debug-iphoneos/libfrontend.a"; sourceTree = ""; }; 37FD7DFF2910094300853C23 /* WenetDemo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = WenetDemo.app; sourceTree = BUILT_PRODUCTS_DIR; }; - 37FD7E022910094300853C23 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; - 37FD7E042910094300853C23 /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = ""; }; - 37FD7E062910094300853C23 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; + 37FD7E022910094300853C23 /* AppDelegate.swift */ = {isa = PBXFileReference; indentWidth = 2; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; tabWidth = 2; }; + 37FD7E042910094300853C23 /* SceneDelegate.swift */ = {isa = PBXFileReference; indentWidth = 2; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = ""; tabWidth = 2; }; + 37FD7E062910094300853C23 /* ViewController.swift */ = {isa = PBXFileReference; indentWidth = 2; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; tabWidth = 2; }; 37FD7E092910094300853C23 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 37FD7E0B2910094500853C23 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 37FD7E0E2910094500853C23 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 37FD7E102910094500853C23 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 37FD7E17291009EC00853C23 /* WenetDemo-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "WenetDemo-Bridging-Header.h"; sourceTree = ""; }; - 37FD7E18291009EC00853C23 /* wenet.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = wenet.mm; sourceTree = ""; }; + 37FD7E18291009EC00853C23 /* wenet.mm */ = {isa = PBXFileReference; indentWidth = 2; lastKnownFileType = sourcecode.cpp.objcpp; path = wenet.mm; sourceTree = ""; tabWidth = 2; }; 37FD7E19291009EC00853C23 /* wenet.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = wenet.h; sourceTree = ""; }; 37FD7E1C2910195900853C23 /* libdecoder.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libdecoder.a; path = "../wenet/runtime/ios/build/decoder/Debug-iphoneos/libdecoder.a"; sourceTree = ""; }; 37FD7E1E2910198A00853C23 /* libeigen_blas.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libeigen_blas.a; path = ../wenet/runtime/ios/build/Pods/LibTorch/install/lib/libeigen_blas.a; sourceTree = ""; }; diff --git a/runtime/ios/WenetDemo/WenetDemo/AppDelegate.swift b/runtime/ios/WenetDemo/WenetDemo/AppDelegate.swift index 6f99512fc5..19ae3160ed 100644 --- a/runtime/ios/WenetDemo/WenetDemo/AppDelegate.swift +++ b/runtime/ios/WenetDemo/WenetDemo/AppDelegate.swift @@ -22,24 +22,36 @@ class AppDelegate: UIResponder, UIApplicationDelegate { - func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { - // Override point for customization after application launch. - return true - } - - // MARK: UISceneSession Lifecycle - - func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration { - // Called when a new scene session is being created. - // Use this method to select a configuration to create the new scene with. - return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role) - } - - func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set) { - // Called when the user discards a scene session. - // If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions. - // Use this method to release any resources that were specific to the discarded scenes, as they will not return. - } + func application(_ application: UIApplication, didFinishLaunchingWithOptions + launchOptions: [UIApplication.LaunchOptionsKey: Any]?) + -> Bool { + // Override point for customization after application launch. + return true + } + + // MARK: UISceneSession Lifecycle + + func application(_ application: UIApplication, configurationForConnecting + connectingSceneSession: UISceneSession, + options: UIScene.ConnectionOptions) + -> UISceneConfiguration { + // Called when a new scene session is being created. + // Use this method to select a configuration + // to create the new scene with. + return UISceneConfiguration(name: "Default Configuration", + sessionRole: connectingSceneSession.role) + } + + func application(_ application: UIApplication, + didDiscardSceneSessions + sceneSessions: Set) { + // Called when the user discards a scene session. + // If any sessions were discarded while the application was not running, + // this will be called shortly after + // application:didFinishLaunchingWithOptions. + // Use this method to release any resources that were specific to + // the discarded scenes, as they will not return. + } } diff --git a/runtime/ios/WenetDemo/WenetDemo/SceneDelegate.swift b/runtime/ios/WenetDemo/WenetDemo/SceneDelegate.swift index b2db94181b..1c61b7853f 100644 --- a/runtime/ios/WenetDemo/WenetDemo/SceneDelegate.swift +++ b/runtime/ios/WenetDemo/WenetDemo/SceneDelegate.swift @@ -8,43 +8,59 @@ import UIKit class SceneDelegate: UIResponder, UIWindowSceneDelegate { - var window: UIWindow? - - - func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) { - // Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`. - // If using a storyboard, the `window` property will automatically be initialized and attached to the scene. - // This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead). - guard let _ = (scene as? UIWindowScene) else { return } - } - - func sceneDidDisconnect(_ scene: UIScene) { - // Called as the scene is being released by the system. - // This occurs shortly after the scene enters the background, or when its session is discarded. - // Release any resources associated with this scene that can be re-created the next time the scene connects. - // The scene may re-connect later, as its session was not necessarily discarded (see `application:didDiscardSceneSessions` instead). - } - - func sceneDidBecomeActive(_ scene: UIScene) { - // Called when the scene has moved from an inactive state to an active state. - // Use this method to restart any tasks that were paused (or not yet started) when the scene was inactive. - } - - func sceneWillResignActive(_ scene: UIScene) { - // Called when the scene will move from an active state to an inactive state. - // This may occur due to temporary interruptions (ex. an incoming phone call). - } - - func sceneWillEnterForeground(_ scene: UIScene) { - // Called as the scene transitions from the background to the foreground. - // Use this method to undo the changes made on entering the background. - } - - func sceneDidEnterBackground(_ scene: UIScene) { - // Called as the scene transitions from the foreground to the background. - // Use this method to save data, release shared resources, and store enough scene-specific state information - // to restore the scene back to its current state. - } + var window: UIWindow? + + + func scene(_ scene: UIScene, willConnectTo session: UISceneSession, + options connectionOptions: UIScene.ConnectionOptions) { + // Use this method to optionally configure and attach the UIWindow + // `window` to the provided UIWindowScene `scene`. + // If using a storyboard, the `window` property will + // automatically be initialized and attached to the scene. + // This delegate does not imply the connecting scene or session + // are new (see + // `application:configurationForConnectingSceneSession` instead). + guard let _ = (scene as? UIWindowScene) else { return } + } + + func sceneDidDisconnect(_ scene: UIScene) { + // Called as the scene is being released by the system. + // This occurs shortly after the scene enters the background, or when + // its session is discarded. + // Release any resources associated with this scene that can be + // re-created the next time the scene connects. + // The scene may re-connect later, as its session was not necessarily + // discarded (see `application:didDiscardSceneSessions` instead). + } + + func sceneDidBecomeActive(_ scene: UIScene) { + // Called when the scene has moved from an inactive state + // to an active state. + // Use this method to restart any tasks that were + // paused (or not yet started) when the scene was inactive. + } + + func sceneWillResignActive(_ scene: UIScene) { + // Called when the scene will move from an active state to + // an inactive state. + // This may occur due to temporary interruptions + // (ex. an incoming phone call). + } + + func sceneWillEnterForeground(_ scene: UIScene) { + // Called as the scene transitions from the background + // to the foreground. + // Use this method to undo the changes made on + // entering the background. + } + + func sceneDidEnterBackground(_ scene: UIScene) { + // Called as the scene transitions from the foreground to + // the background. + // Use this method to save data, release shared resources, + // and store enough scene-specific state information + // to restore the scene back to its current state. + } } diff --git a/runtime/ios/WenetDemo/WenetDemo/ViewController.swift b/runtime/ios/WenetDemo/WenetDemo/ViewController.swift index 5efada2962..707073a2d2 100644 --- a/runtime/ios/WenetDemo/WenetDemo/ViewController.swift +++ b/runtime/ios/WenetDemo/WenetDemo/ViewController.swift @@ -20,109 +20,124 @@ import AVFoundation class ViewController: UIViewController { - @IBOutlet weak var label: UILabel! - @IBOutlet weak var button: UIButton! - - var wenetModel: Wenet? - var audioEngine: AVAudioEngine? - var startRecord: Bool? - private var workItem: DispatchWorkItem? - - override func viewDidLoad() { - super.viewDidLoad() - // Do any additional setup after loading the view. - - initModel() - - initRecorder() - } - - func initModel() { - let modelPath = Bundle.main.path(forResource: "final", ofType: "zip") - let dictPath = Bundle.main.path(forResource: "units", ofType: "txt") - wenetModel = Wenet(modelPath:modelPath, dictPath:dictPath)! - - wenetModel?.reset() - } - - func initRecorder() { - startRecord = false - - audioEngine = AVAudioEngine() - let inputNode = self.audioEngine?.inputNode - let bus = 0 - let inputFormat = inputNode?.outputFormat(forBus: bus) - let outputFormat = AVAudioFormat(commonFormat: .pcmFormatFloat32, sampleRate: 16000, channels: 1, interleaved: false)! - let converter = AVAudioConverter(from: inputFormat!, to: outputFormat)! - inputNode!.installTap(onBus: bus, bufferSize: 1024, format: inputFormat) { (buffer: AVAudioPCMBuffer, when: AVAudioTime) in - var newBufferAvailable = true - - let inputCallback: AVAudioConverterInputBlock = { inNumPackets, outStatus in - if newBufferAvailable { - outStatus.pointee = .haveData - newBufferAvailable = false - - return buffer - } else { - outStatus.pointee = .noDataNow - return nil - } - } - - let convertedBuffer = AVAudioPCMBuffer(pcmFormat: outputFormat, frameCapacity: AVAudioFrameCount(outputFormat.sampleRate) * buffer.frameLength / AVAudioFrameCount(buffer.format.sampleRate))! - - var error: NSError? - let status = converter.convert(to: convertedBuffer, error: &error, withInputFrom: inputCallback) - - // 16000 Hz buffer - let actualSampleCount = Int(convertedBuffer.frameLength) - guard let floatChannelData = convertedBuffer.floatChannelData else { return } - - self.wenetModel?.acceptWaveForm(floatChannelData[0], Int32(actualSampleCount)) + @IBOutlet weak var label: UILabel! + @IBOutlet weak var button: UIButton! + + var wenetModel: Wenet? + var audioEngine: AVAudioEngine? + var startRecord: Bool? + private var workItem: DispatchWorkItem? + + override func viewDidLoad() { + super.viewDidLoad() + // Do any additional setup after loading the view. + + initModel() + + initRecorder() + } + + func initModel() { + let modelPath = Bundle.main.path(forResource: "final", ofType: "zip") + let dictPath = Bundle.main.path(forResource: "units", ofType: "txt") + wenetModel = Wenet(modelPath:modelPath, dictPath:dictPath)! + + wenetModel?.reset() + } + + func initRecorder() { + startRecord = false + + audioEngine = AVAudioEngine() + let inputNode = self.audioEngine?.inputNode + let bus = 0 + let inputFormat = inputNode?.outputFormat(forBus: bus) + let outputFormat = AVAudioFormat(commonFormat: .pcmFormatFloat32, + sampleRate: 16000, channels: 1, + interleaved: false)! + let converter = AVAudioConverter(from: inputFormat!, to: outputFormat)! + inputNode!.installTap(onBus: bus, + bufferSize: 1024, + format: inputFormat) { + (buffer: AVAudioPCMBuffer, when: AVAudioTime) in + var newBufferAvailable = true + + let inputCallback: AVAudioConverterInputBlock = { + inNumPackets, outStatus in + if newBufferAvailable { + outStatus.pointee = .haveData + newBufferAvailable = false + + return buffer + } else { + outStatus.pointee = .noDataNow + return nil } + } + + let convertedBuffer = AVAudioPCMBuffer( + pcmFormat: outputFormat, + frameCapacity: + AVAudioFrameCount(outputFormat.sampleRate) + * buffer.frameLength + / AVAudioFrameCount(buffer.format.sampleRate))! + + var error: NSError? + let status = converter.convert( + to: convertedBuffer, + error: &error, withInputFrom: inputCallback) + + // 16000 Hz buffer + let actualSampleCount = Int(convertedBuffer.frameLength) + guard let floatChannelData = convertedBuffer.floatChannelData + else { return } + + self.wenetModel?.acceptWaveForm(floatChannelData[0], + Int32(actualSampleCount)) } + } + + @IBAction func btnClicked(_ sender: Any) { + if(!startRecord!) { + //Clear result + self.setResult(text: "") + + //Reset model + self.wenetModel?.reset() + + //Start record + do { + try self.audioEngine?.start() + } catch let error as NSError { + print("Got an error starting audioEngine: \(error.domain), \(error)") + } + + //Start decode thread + workItem = DispatchWorkItem { + while(!self.workItem!.isCancelled) { + self.wenetModel?.decode() + DispatchQueue.main.sync { + self.setResult(text: (self.wenetModel?.get_result())!) + } + } + } + DispatchQueue.global().async(execute: workItem!) - @IBAction func btnClicked(_ sender: Any) { - if(!startRecord!) { - //Clear result - self.setResult(text: "") - - //Reset model - self.wenetModel?.reset() - - //Start record - do { - try self.audioEngine?.start() - } catch let error as NSError { - print("Got an error starting audioEngine: \(error.domain), \(error)") - } - - //Start decode thread - workItem = DispatchWorkItem { - while(!self.workItem!.isCancelled) { - self.wenetModel?.decode() - DispatchQueue.main.sync { - self.setResult(text: (self.wenetModel?.get_result())!) - } - } - } - DispatchQueue.global().async(execute: workItem!) - - startRecord = true - button.setTitle("Stop Record", for: UIControl.State.normal) - } else { - //Stop record - self.audioEngine?.stop() + startRecord = true + button.setTitle("Stop Record", for: UIControl.State.normal) + } else { + //Stop record + self.audioEngine?.stop() - //Stop decode thread - workItem!.cancel() + //Stop decode thread + workItem!.cancel() - startRecord = false - button.setTitle("Start Record", for: UIControl.State.normal) - } + startRecord = false + button.setTitle("Start Record", for: UIControl.State.normal) } + } - @objc func setResult(text: String) { - label.text = text - } + @objc func setResult(text: String) { + label.text = text + } } diff --git a/runtime/ios/WenetDemo/WenetDemo/wenet/wenet.h b/runtime/ios/WenetDemo/WenetDemo/wenet/wenet.h index 676fabcca6..0d430e3577 100644 --- a/runtime/ios/WenetDemo/WenetDemo/wenet/wenet.h +++ b/runtime/ios/WenetDemo/WenetDemo/wenet/wenet.h @@ -24,7 +24,8 @@ @interface Wenet : NSObject -- (nullable instancetype)initWithModelPath:(NSString*)modelPath DictPath:(NSString*)dictPath; // NOLINT +- (nullable instancetype)initWithModelPath: +(NSString*)modelPath DictPath:(NSString*)dictPath; // NOLINT - (void)reset; diff --git a/runtime/ios/WenetDemo/WenetDemo/wenet/wenet.mm b/runtime/ios/WenetDemo/WenetDemo/wenet/wenet.mm index 6936f604f8..bab9a085ca 100644 --- a/runtime/ios/WenetDemo/WenetDemo/wenet/wenet.mm +++ b/runtime/ios/WenetDemo/WenetDemo/wenet/wenet.mm @@ -31,99 +31,105 @@ @implementation Wenet { @protected - std::shared_ptr decode_config; - std::shared_ptr feature_config; - std::shared_ptr feature_pipeline; - std::shared_ptr decoder; - std::shared_ptr resource; - DecodeState state; - std::string total_result; + std::shared_ptr decode_config; + std::shared_ptr feature_config; + std::shared_ptr feature_pipeline; + std::shared_ptr decoder; + std::shared_ptr resource; + DecodeState state; + std::string total_result; } -- (nullable instancetype)initWithModelPath:(NSString*)modelPath DictPath:(NSString*)dictPath { - self = [super init]; - if (self) { - try { - auto qengines = at::globalContext().supportedQEngines(); - if (std::find(qengines.begin(), qengines.end(), at::QEngine::QNNPACK) != qengines.end()) { - at::globalContext().setQEngine(at::QEngine::QNNPACK); - } - auto model = std::make_shared(); - model->Read(modelPath.UTF8String); - resource = std::make_shared(); - resource->model = model; - resource->symbol_table = std::shared_ptr( - fst::SymbolTable::ReadText(dictPath.UTF8String)); - - PostProcessOptions post_process_opts; - resource->post_processor = std::make_shared(post_process_opts); - - feature_config = std::make_shared(80, 16000); - feature_pipeline = std::make_shared(*feature_config); - - decode_config = std::make_shared(); - decode_config->chunk_size = 16; - decoder = std::make_shared(feature_pipeline, resource, *decode_config); - - state = kEndBatch; - } catch (const std::exception& exception) { - NSLog(@"%s", exception.what()); - return nil; - } +- (nullable instancetype)initWithModelPath: +(NSString*)modelPath DictPath:(NSString*)dictPath { + self = [super init]; + if (self) { + try { + auto qengines = at::globalContext().supportedQEngines(); + if (std::find(qengines.begin(), qengines.end(), at::QEngine::QNNPACK) + != qengines.end()) { + at::globalContext().setQEngine(at::QEngine::QNNPACK); + } + auto model = std::make_shared(); + model->Read(modelPath.UTF8String); + resource = std::make_shared(); + resource->model = model; + resource->symbol_table = std::shared_ptr + (fst::SymbolTable::ReadText(dictPath.UTF8String)); + + PostProcessOptions post_process_opts; + resource->post_processor = + std::make_shared(post_process_opts); + + feature_config = std::make_shared(80, 16000); + feature_pipeline = std::make_shared(*feature_config); + + decode_config = std::make_shared(); + decode_config->chunk_size = 16; + decoder = std::make_shared(feature_pipeline, + resource, + *decode_config); + + state = kEndBatch; + } catch (const std::exception& exception) { + NSLog(@"%s", exception.what()); + return nil; } + } - return self; + return self; } - (void)reset { - decoder->Reset(); - state = kEndBatch; - total_result = ""; + decoder->Reset(); + state = kEndBatch; + total_result = ""; } - (void)acceptWaveForm: (float*)pcm: (int)size { - auto* float_pcm = new float[size]; - for (size_t i = 0; i < size; i++) { - float_pcm[i] = pcm[i] * 65535; - } - feature_pipeline->AcceptWaveform(float_pcm, size); + auto* float_pcm = new float[size]; + for (size_t i = 0; i < size; i++) { + float_pcm[i] = pcm[i] * 65535; + } + feature_pipeline->AcceptWaveform(float_pcm, size); } - (void)decode { - state = decoder->Decode(); - if (state == kEndFeats || state == kEndpoint) { - decoder->Rescoring(); - } - - std::string result; + state = decoder->Decode(); + if (state == kEndFeats || state == kEndpoint) { + decoder->Rescoring(); + } + + std::string result; + if (decoder->DecodedSomething()) { + result = decoder->result()[0].sentence; + } + + if (state == kEndFeats) { + LOG(INFO) << "wenet endfeats final result: " << result; + NSLog(@"wenet endfeats final result: %s", result.c_str()); + total_result += result; + } else if (state == kEndpoint) { + LOG(INFO) << "wenet endpoint final result: " << result; + NSLog(@"wenet endpoint final result: %s", result.c_str()); + total_result += result + ","; + decoder->ResetContinuousDecoding(); + } else { if (decoder->DecodedSomething()) { - result = decoder->result()[0].sentence; - } - - if (state == kEndFeats) { - LOG(INFO) << "wenet endfeats final result: " << result; - NSLog(@"wenet endfeats final result: %s", result.c_str()); - total_result += result; - } else if (state == kEndpoint) { - LOG(INFO) << "wenet endpoint final result: " << result; - NSLog(@"wenet endpoint final result: %s", result.c_str()); - total_result += result + ","; - decoder->ResetContinuousDecoding(); - } else { - if (decoder->DecodedSomething()) { - LOG(INFO) << "wenet partial result: " << result; - } + LOG(INFO) << "wenet partial result: " << result; + NSLog(@"wenet partial result: %s", result.c_str()); } + } } - (NSString*)get_result { - std::string result; - if (decoder->DecodedSomething()) { - result = decoder->result()[0].sentence; - } - LOG(INFO) << "wenet ui result: " << total_result + result; - NSLog(@"wenet ui result: %s", (total_result + result).c_str()); - return [NSString stringWithUTF8String:(total_result + result).c_str()]; + std::string result; + if (decoder->DecodedSomething()) { + result = decoder->result()[0].sentence; + } + LOG(INFO) << "wenet ui result: " << total_result + result; + NSLog(@"wenet ui result: %s", (total_result + result).c_str()); + return [NSString stringWithUTF8String:(total_result + result).c_str()]; } @end