正在显示
5 个修改的文件
包含
82 行增加
和
17 行删除
| @@ -50,11 +50,30 @@ jobs: | @@ -50,11 +50,30 @@ jobs: | ||
| 50 | cmake -DBUILD_SHARED_LIBS=ON -DCMAKE_INSTALL_PREFIX=./install -DCMAKE_BUILD_TYPE=Release .. | 50 | cmake -DBUILD_SHARED_LIBS=ON -DCMAKE_INSTALL_PREFIX=./install -DCMAKE_BUILD_TYPE=Release .. |
| 51 | cmake --build . --target install --config Release | 51 | cmake --build . --target install --config Release |
| 52 | 52 | ||
| 53 | + - name: Build sherpa-onnx for windows x86 | ||
| 54 | + if: matrix.os == 'windows-latest' | ||
| 55 | + shell: bash | ||
| 56 | + run: | | ||
| 57 | + export CMAKE_CXX_COMPILER_LAUNCHER=ccache | ||
| 58 | + export PATH="/usr/lib/ccache:/usr/local/opt/ccache/libexec:$PATH" | ||
| 59 | + cmake --version | ||
| 60 | + | ||
| 61 | + mkdir build-win32 | ||
| 62 | + cd build-win32 | ||
| 63 | + cmake -A Win32 -DBUILD_SHARED_LIBS=ON -DCMAKE_INSTALL_PREFIX=./install -DCMAKE_BUILD_TYPE=Release .. | ||
| 64 | + cmake --build . --target install --config Release | ||
| 65 | + | ||
| 53 | - uses: actions/upload-artifact@v4 | 66 | - uses: actions/upload-artifact@v4 |
| 54 | with: | 67 | with: |
| 55 | name: ${{ matrix.os }} | 68 | name: ${{ matrix.os }} |
| 56 | path: ./build/install/lib/ | 69 | path: ./build/install/lib/ |
| 57 | 70 | ||
| 71 | + - uses: actions/upload-artifact@v4 | ||
| 72 | + if: matrix.os == 'windows-latest' | ||
| 73 | + with: | ||
| 74 | + name: ${{ matrix.os }}-win32 | ||
| 75 | + path: ./build-win32/install/lib/ | ||
| 76 | + | ||
| 58 | test-dot-net: | 77 | test-dot-net: |
| 59 | runs-on: ${{ matrix.os }} | 78 | runs-on: ${{ matrix.os }} |
| 60 | needs: [build-libs] | 79 | needs: [build-libs] |
| @@ -95,7 +114,13 @@ jobs: | @@ -95,7 +114,13 @@ jobs: | ||
| 95 | uses: actions/download-artifact@v4 | 114 | uses: actions/download-artifact@v4 |
| 96 | with: | 115 | with: |
| 97 | name: windows-latest | 116 | name: windows-latest |
| 98 | - path: /tmp/windows | 117 | + path: /tmp/windows-x64 |
| 118 | + | ||
| 119 | + - name: Retrieve artifact from windows-latest | ||
| 120 | + uses: actions/download-artifact@v4 | ||
| 121 | + with: | ||
| 122 | + name: windows-latest-win32 | ||
| 123 | + path: /tmp/windows-x86 | ||
| 99 | 124 | ||
| 100 | - name: Setup .NET | 125 | - name: Setup .NET |
| 101 | uses: actions/setup-dotnet@v3 | 126 | uses: actions/setup-dotnet@v3 |
| @@ -119,8 +144,11 @@ jobs: | @@ -119,8 +144,11 @@ jobs: | ||
| 119 | echo "----------/tmp/macos----------" | 144 | echo "----------/tmp/macos----------" |
| 120 | ls -lh /tmp/macos | 145 | ls -lh /tmp/macos |
| 121 | 146 | ||
| 122 | - echo "----------/tmp/windows----------" | ||
| 123 | - ls -lh /tmp/windows | 147 | + echo "----------/tmp/windows-x64----------" |
| 148 | + ls -lh /tmp/windows-x64 | ||
| 149 | + | ||
| 150 | + echo "----------/tmp/windows-x86----------" | ||
| 151 | + ls -lh /tmp/windows-x86 | ||
| 124 | 152 | ||
| 125 | - name: Build | 153 | - name: Build |
| 126 | shell: bash | 154 | shell: bash |
| @@ -87,7 +87,7 @@ def process_macos(s): | @@ -87,7 +87,7 @@ def process_macos(s): | ||
| 87 | f.write(s) | 87 | f.write(s) |
| 88 | 88 | ||
| 89 | 89 | ||
| 90 | -def process_windows(s): | 90 | +def process_windows(s, rid): |
| 91 | libs = [ | 91 | libs = [ |
| 92 | "espeak-ng.dll", | 92 | "espeak-ng.dll", |
| 93 | "kaldi-decoder-core.dll", | 93 | "kaldi-decoder-core.dll", |
| @@ -103,18 +103,18 @@ def process_windows(s): | @@ -103,18 +103,18 @@ def process_windows(s): | ||
| 103 | 103 | ||
| 104 | version = get_version() | 104 | version = get_version() |
| 105 | 105 | ||
| 106 | - prefix = "/tmp/windows/" | 106 | + prefix = f"/tmp/windows-{rid}/" |
| 107 | libs = [prefix + lib for lib in libs] | 107 | libs = [prefix + lib for lib in libs] |
| 108 | libs = "\n ;".join(libs) | 108 | libs = "\n ;".join(libs) |
| 109 | 109 | ||
| 110 | d = get_dict() | 110 | d = get_dict() |
| 111 | - d["dotnet_rid"] = "win-x64" | 111 | + d["dotnet_rid"] = f"win-{rid}" |
| 112 | d["libs"] = libs | 112 | d["libs"] = libs |
| 113 | 113 | ||
| 114 | environment = jinja2.Environment() | 114 | environment = jinja2.Environment() |
| 115 | template = environment.from_string(s) | 115 | template = environment.from_string(s) |
| 116 | s = template.render(**d) | 116 | s = template.render(**d) |
| 117 | - with open("./windows/sherpa-onnx.runtime.csproj", "w") as f: | 117 | + with open(f"./windows-{rid}/sherpa-onnx.runtime.csproj", "w") as f: |
| 118 | f.write(s) | 118 | f.write(s) |
| 119 | 119 | ||
| 120 | 120 | ||
| @@ -122,7 +122,8 @@ def main(): | @@ -122,7 +122,8 @@ def main(): | ||
| 122 | s = read_proj_file("./sherpa-onnx.csproj.runtime.in") | 122 | s = read_proj_file("./sherpa-onnx.csproj.runtime.in") |
| 123 | process_macos(s) | 123 | process_macos(s) |
| 124 | process_linux(s) | 124 | process_linux(s) |
| 125 | - process_windows(s) | 125 | + process_windows(s, "x64") |
| 126 | + process_windows(s, "x86") | ||
| 126 | 127 | ||
| 127 | s = read_proj_file("./sherpa-onnx.csproj.in") | 128 | s = read_proj_file("./sherpa-onnx.csproj.in") |
| 128 | d = get_dict() | 129 | d = get_dict() |
| @@ -16,14 +16,15 @@ HF_MIRROR=hf.co | @@ -16,14 +16,15 @@ HF_MIRROR=hf.co | ||
| 16 | mkdir -p /tmp/ | 16 | mkdir -p /tmp/ |
| 17 | pushd /tmp | 17 | pushd /tmp |
| 18 | 18 | ||
| 19 | -mkdir -p linux macos windows | 19 | +mkdir -p linux macos windows-x64 windows-x86 |
| 20 | 20 | ||
| 21 | # You can pre-download the required wheels to /tmp | 21 | # You can pre-download the required wheels to /tmp |
| 22 | src_dir=/tmp | 22 | src_dir=/tmp |
| 23 | 23 | ||
| 24 | linux_wheel=$src_dir/sherpa_onnx-${SHERPA_ONNX_VERSION}-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl | 24 | linux_wheel=$src_dir/sherpa_onnx-${SHERPA_ONNX_VERSION}-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
| 25 | macos_wheel=$src_dir/sherpa_onnx-${SHERPA_ONNX_VERSION}-cp38-cp38-macosx_11_0_x86_64.whl | 25 | macos_wheel=$src_dir/sherpa_onnx-${SHERPA_ONNX_VERSION}-cp38-cp38-macosx_11_0_x86_64.whl |
| 26 | -windows_wheel=$src_dir/sherpa_onnx-${SHERPA_ONNX_VERSION}-cp38-cp38-win_amd64.whl | 26 | +windows_x64_wheel=$src_dir/sherpa_onnx-${SHERPA_ONNX_VERSION}-cp38-cp38-win_amd64.whl |
| 27 | +windows_x86_wheel=$src_dir/sherpa_onnx-${SHERPA_ONNX_VERSION}-cp38-cp38-win32.whl | ||
| 27 | 28 | ||
| 28 | if [ ! -f /tmp/linux/libsherpa-onnx-core.so ]; then | 29 | if [ ! -f /tmp/linux/libsherpa-onnx-core.so ]; then |
| 29 | echo "---linux x86_64---" | 30 | echo "---linux x86_64---" |
| @@ -72,13 +73,13 @@ if [ ! -f /tmp/macos/libsherpa-onnx-core.dylib ]; then | @@ -72,13 +73,13 @@ if [ ! -f /tmp/macos/libsherpa-onnx-core.dylib ]; then | ||
| 72 | fi | 73 | fi |
| 73 | 74 | ||
| 74 | 75 | ||
| 75 | -if [ ! -f /tmp/windows/sherpa-onnx-core.dll ]; then | 76 | +if [ ! -f /tmp/windows-x64/sherpa-onnx-core.dll ]; then |
| 76 | echo "---windows x64---" | 77 | echo "---windows x64---" |
| 77 | - cd windows | 78 | + cd windows-x64 |
| 78 | mkdir -p wheel | 79 | mkdir -p wheel |
| 79 | cd wheel | 80 | cd wheel |
| 80 | - if [ -f $windows_wheel ]; then | ||
| 81 | - cp -v $windows_wheel . | 81 | + if [ -f $windows_x64_wheel ]; then |
| 82 | + cp -v $windows_x64_wheel . | ||
| 82 | else | 83 | else |
| 83 | curl -OL https://$HF_MIRROR/csukuangfj/sherpa-onnx-wheels/resolve/main/sherpa_onnx-${SHERPA_ONNX_VERSION}-cp38-cp38-win_amd64.whl | 84 | curl -OL https://$HF_MIRROR/csukuangfj/sherpa-onnx-wheels/resolve/main/sherpa_onnx-${SHERPA_ONNX_VERSION}-cp38-cp38-win_amd64.whl |
| 84 | fi | 85 | fi |
| @@ -92,9 +93,29 @@ if [ ! -f /tmp/windows/sherpa-onnx-core.dll ]; then | @@ -92,9 +93,29 @@ if [ ! -f /tmp/windows/sherpa-onnx-core.dll ]; then | ||
| 92 | cd .. | 93 | cd .. |
| 93 | fi | 94 | fi |
| 94 | 95 | ||
| 96 | +if [ ! -f /tmp/windows-x86/sherpa-onnx-core.dll ]; then | ||
| 97 | + echo "---windows x86---" | ||
| 98 | + cd windows-x86 | ||
| 99 | + mkdir -p wheel | ||
| 100 | + cd wheel | ||
| 101 | + if [ -f $windows_x86_wheel ]; then | ||
| 102 | + cp -v $windows_x86_wheel . | ||
| 103 | + else | ||
| 104 | + curl -OL https://$HF_MIRROR/csukuangfj/sherpa-onnx-wheels/resolve/main/sherpa_onnx-${SHERPA_ONNX_VERSION}-cp38-cp38-win32.whl | ||
| 105 | + fi | ||
| 106 | + unzip sherpa_onnx-${SHERPA_ONNX_VERSION}-cp38-cp38-win32.whl | ||
| 107 | + cp -v sherpa_onnx-${SHERPA_ONNX_VERSION}.data/data/bin/*.dll ../ | ||
| 108 | + cp -v sherpa_onnx-${SHERPA_ONNX_VERSION}.data/data/bin/*.lib ../ | ||
| 109 | + cd .. | ||
| 110 | + | ||
| 111 | + rm -rf wheel | ||
| 112 | + ls -lh | ||
| 113 | + cd .. | ||
| 114 | +fi | ||
| 115 | + | ||
| 95 | popd | 116 | popd |
| 96 | 117 | ||
| 97 | -mkdir -p macos linux windows all | 118 | +mkdir -p macos linux windows-x64 windows-x86 all |
| 98 | 119 | ||
| 99 | cp ./online.cs all | 120 | cp ./online.cs all |
| 100 | cp ./offline.cs all | 121 | cp ./offline.cs all |
| @@ -111,7 +132,12 @@ dotnet build -c Release | @@ -111,7 +132,12 @@ dotnet build -c Release | ||
| 111 | dotnet pack -c Release -o ../packages | 132 | dotnet pack -c Release -o ../packages |
| 112 | popd | 133 | popd |
| 113 | 134 | ||
| 114 | -pushd windows | 135 | +pushd windows-x64 |
| 136 | +dotnet build -c Release | ||
| 137 | +dotnet pack -c Release -o ../packages | ||
| 138 | +popd | ||
| 139 | + | ||
| 140 | +pushd windows-x86 | ||
| 115 | dotnet build -c Release | 141 | dotnet build -c Release |
| 116 | dotnet pack -c Release -o ../packages | 142 | dotnet pack -c Release -o ../packages |
| 117 | popd | 143 | popd |
| @@ -51,6 +51,7 @@ | @@ -51,6 +51,7 @@ | ||
| 51 | <PackageReference Include="org.k2fsa.sherpa.onnx.runtime.linux-x64" Version="{{ version }}" /> | 51 | <PackageReference Include="org.k2fsa.sherpa.onnx.runtime.linux-x64" Version="{{ version }}" /> |
| 52 | <PackageReference Include="org.k2fsa.sherpa.onnx.runtime.osx-x64" Version="{{ version }}" /> | 52 | <PackageReference Include="org.k2fsa.sherpa.onnx.runtime.osx-x64" Version="{{ version }}" /> |
| 53 | <PackageReference Include="org.k2fsa.sherpa.onnx.runtime.win-x64" Version="{{ version }}" /> | 53 | <PackageReference Include="org.k2fsa.sherpa.onnx.runtime.win-x64" Version="{{ version }}" /> |
| 54 | + <PackageReference Include="org.k2fsa.sherpa.onnx.runtime.win-x86" Version="{{ version }}" /> | ||
| 54 | </ItemGroup> | 55 | </ItemGroup> |
| 55 | 56 | ||
| 56 | </Project> | 57 | </Project> |
| @@ -145,7 +145,9 @@ std::vector<std::vector<int64_t>> Lexicon::ConvertTextToTokenIds( | @@ -145,7 +145,9 @@ std::vector<std::vector<int64_t>> Lexicon::ConvertTextToTokenIds( | ||
| 145 | } | 145 | } |
| 146 | 146 | ||
| 147 | std::vector<std::vector<int64_t>> Lexicon::ConvertTextToTokenIdsChinese( | 147 | std::vector<std::vector<int64_t>> Lexicon::ConvertTextToTokenIdsChinese( |
| 148 | - const std::string &text) const { | 148 | + const std::string &_text) const { |
| 149 | + std::string text(_text); | ||
| 150 | + ToLowerCase(&text); | ||
| 149 | std::vector<std::string> words; | 151 | std::vector<std::string> words; |
| 150 | if (pattern_) { | 152 | if (pattern_) { |
| 151 | // Handle polyphones | 153 | // Handle polyphones |
| @@ -206,6 +208,11 @@ std::vector<std::vector<int64_t>> Lexicon::ConvertTextToTokenIdsChinese( | @@ -206,6 +208,11 @@ std::vector<std::vector<int64_t>> Lexicon::ConvertTextToTokenIdsChinese( | ||
| 206 | eos = token2id_.at("eos"); | 208 | eos = token2id_.at("eos"); |
| 207 | } | 209 | } |
| 208 | 210 | ||
| 211 | + int32_t pad = -1; | ||
| 212 | + if (token2id_.count("#0")) { | ||
| 213 | + pad = token2id_.at("#0"); | ||
| 214 | + } | ||
| 215 | + | ||
| 209 | if (sil != -1) { | 216 | if (sil != -1) { |
| 210 | this_sentence.push_back(sil); | 217 | this_sentence.push_back(sil); |
| 211 | } | 218 | } |
| @@ -219,6 +226,8 @@ std::vector<std::vector<int64_t>> Lexicon::ConvertTextToTokenIdsChinese( | @@ -219,6 +226,8 @@ std::vector<std::vector<int64_t>> Lexicon::ConvertTextToTokenIdsChinese( | ||
| 219 | if (punctuations_.count(w)) { | 226 | if (punctuations_.count(w)) { |
| 220 | if (token2id_.count(w)) { | 227 | if (token2id_.count(w)) { |
| 221 | this_sentence.push_back(token2id_.at(w)); | 228 | this_sentence.push_back(token2id_.at(w)); |
| 229 | + } else if (pad != -1) { | ||
| 230 | + this_sentence.push_back(pad); | ||
| 222 | } else if (sil != -1) { | 231 | } else if (sil != -1) { |
| 223 | this_sentence.push_back(sil); | 232 | this_sentence.push_back(sil); |
| 224 | } | 233 | } |
-
请 注册 或 登录 后发表评论