Toggle navigation
Toggle navigation
此项目
正在载入...
Sign in
xuning
/
sherpaonnx
转到一个项目
Toggle navigation
项目
群组
代码片段
帮助
Toggle navigation pinning
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Authored by
Fangjun Kuang
2024-05-30 16:19:56 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Committed by
GitHub
2024-05-30 16:19:56 +0800
Commit
a99c7cb35ccdc1f36926a8dae70b9a7b283b7979
a99c7cb3
1 parent
082f230d
Wrap punctuation APIs to C#. (#945)
显示空白字符变更
内嵌
并排对比
正在显示
31 个修改的文件
包含
242 行增加
和
34 行删除
.github/scripts/test-dot-net.sh
.github/workflows/test-dot-net.yaml
dotnet-examples/offline-punctuation/Program.cs
dotnet-examples/offline-punctuation/offline-punctuation.csproj
dotnet-examples/offline-punctuation/run.sh
dotnet-examples/sherpa-onnx.sln
scripts/dotnet/FeatureConfig.cs
scripts/dotnet/OfflineLMConfig.cs
scripts/dotnet/OfflineModelConfig.cs
scripts/dotnet/OfflineNemoEncDecCtcModelConfig.cs
scripts/dotnet/OfflineParaformerModelConfig.cs
scripts/dotnet/OfflinePunctuation.cs
scripts/dotnet/OfflinePunctuationConfig.cs
scripts/dotnet/OfflinePunctuationModelConfig.cs
scripts/dotnet/OfflineRecognizer.cs
scripts/dotnet/OfflineRecognizerConfig.cs
scripts/dotnet/OfflineRecognizerResult.cs
scripts/dotnet/OfflineStream.cs
scripts/dotnet/OfflineTdnnModelConfig.cs
scripts/dotnet/OfflineTransducerModelConfig.cs
scripts/dotnet/OfflineTtsConfig.cs
scripts/dotnet/OfflineTtsModelConfig.cs
scripts/dotnet/OfflineWhisperModelConfig.cs
scripts/dotnet/OnlineCtcFstDecoderConfig.cs
scripts/dotnet/OnlineModelConfig.cs
scripts/dotnet/OnlineParaformerModelConfig.cs
scripts/dotnet/OnlineRecognizerConfig.cs
scripts/dotnet/OnlineRecognizerResult.cs
scripts/dotnet/OnlineStream.cs
scripts/dotnet/OnlineTransducerModelConfig.cs
scripts/dotnet/examples/offline-punctuation.csproj
.github/scripts/test-dot-net.sh
查看文件 @
a99c7cb
...
...
@@ -2,7 +2,10 @@
cd
dotnet-examples/
cd
speaker-identification
cd
offline-punctuation
./run.sh
cd
../speaker-identification
./run.sh
cd
../streaming-hlg-decoding/
...
...
.github/workflows/test-dot-net.yaml
查看文件 @
a99c7cb
...
...
@@ -196,6 +196,7 @@ jobs:
cp -v scripts/dotnet/examples/spoken-language-identification.csproj dotnet-examples/spoken-language-identification/
cp -v scripts/dotnet/examples/streaming-hlg-decoding.csproj dotnet-examples/streaming-hlg-decoding
cp -v scripts/dotnet/examples/speaker-identification.csproj dotnet-examples/speaker-identification
cp -v scripts/dotnet/examples/offline-punctuation.csproj dotnet-examples/offline-punctuation
ls -lh /tmp
...
...
dotnet-examples/offline-punctuation/Program.cs
0 → 100644
查看文件 @
a99c7cb
// Copyright (c) 2024 Xiaomi Corporation
//
// This file shows how to add punctuations to text.
//
// 1. Download a model from
// https://github.com/k2-fsa/sherpa-onnx/releases/tag/punctuation-models
//
// wget https://github.com/k2-fsa/sherpa-onnx/releases/download/punctuation-models/sherpa-onnx-punct-ct-transformer-zh-en-vocab272727-2024-04-12.tar.bz2
//
// 3. Now run it
//
// dotnet run
using
SherpaOnnx
;
using
System.Collections.Generic
;
using
System
;
class
OfflinePunctuationDemo
{
static
void
Main
(
string
[]
args
)
{
var
config
=
new
OfflinePunctuationConfig
();
config
.
Model
.
CtTransformer
=
"./sherpa-onnx-punct-ct-transformer-zh-en-vocab272727-2024-04-12/model.onnx"
;
config
.
Model
.
Debug
=
1
;
config
.
Model
.
NumThreads
=
1
;
var
punct
=
new
OfflinePunctuation
(
config
);
string
[]
textList
=
new
string
[]
{
"这是一个测试你好吗How are you我很好thank you are you ok谢谢你"
,
"我们都是木头人不会说话不会动"
,
"The African blogosphere is rapidly expanding bringing more voices online in the form of commentaries opinions analyses rants and poetry"
,
};
Console
.
WriteLine
(
"---------"
);
foreach
(
string
text
in
textList
)
{
string
textWithPunct
=
punct
.
AddPunct
(
text
);
Console
.
WriteLine
(
"Input text: {0}"
,
text
);
Console
.
WriteLine
(
"Output text: {0}"
,
textWithPunct
);
Console
.
WriteLine
(
"---------"
);
}
}
}
...
...
dotnet-examples/offline-punctuation/offline-punctuation.csproj
0 → 100644
查看文件 @
a99c7cb
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<RootNamespace>offline_punctuation</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="org.k2fsa.sherpa.onnx" Version="*" />
</ItemGroup>
</Project>
...
...
dotnet-examples/offline-punctuation/run.sh
0 → 100755
查看文件 @
a99c7cb
#!/usr/bin/env bash
set
-ex
if
[
! -e ./sherpa-onnx-punct-ct-transformer-zh-en-vocab272727-2024-04-12/model.onnx
]
;
then
curl -SL -O https://github.com/k2-fsa/sherpa-onnx/releases/download/punctuation-models/sherpa-onnx-punct-ct-transformer-zh-en-vocab272727-2024-04-12.tar.bz2
tar xvf sherpa-onnx-punct-ct-transformer-zh-en-vocab272727-2024-04-12.tar.bz2
rm sherpa-onnx-punct-ct-transformer-zh-en-vocab272727-2024-04-12.tar.bz2
fi
dotnet run
...
...
dotnet-examples/sherpa-onnx.sln
查看文件 @
a99c7cb
...
...
@@ -19,6 +19,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "streaming-hlg-decoding", "s
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "speaker-identification", "speaker-identification\speaker-identification.csproj", "{2B1B140E-A92F-426B-B0DF-5D916B67304F}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "offline-punctuation", "offline-punctuation\offline-punctuation.csproj", "{42D85582-BB63-4259-A4EA-837D66AC078B}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
...
...
@@ -60,5 +62,9 @@ Global
{2B1B140E-A92F-426B-B0DF-5D916B67304F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2B1B140E-A92F-426B-B0DF-5D916B67304F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2B1B140E-A92F-426B-B0DF-5D916B67304F}.Release|Any CPU.Build.0 = Release|Any CPU
{42D85582-BB63-4259-A4EA-837D66AC078B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{42D85582-BB63-4259-A4EA-837D66AC078B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{42D85582-BB63-4259-A4EA-837D66AC078B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{42D85582-BB63-4259-A4EA-837D66AC078B}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal
...
...
scripts/dotnet/FeatureConfig.cs
查看文件 @
a99c7cb
scripts/dotnet/OfflineLMConfig.cs
查看文件 @
a99c7cb
...
...
@@ -8,7 +8,6 @@ using System;
namespace
SherpaOnnx
{
[
StructLayout
(
LayoutKind
.
Sequential
)]
public
struct
OfflineLMConfig
{
...
...
@@ -22,5 +21,4 @@ namespace SherpaOnnx
public
float
Scale
;
}
}
...
...
scripts/dotnet/OfflineModelConfig.cs
查看文件 @
a99c7cb
...
...
@@ -8,7 +8,6 @@ using System;
namespace
SherpaOnnx
{
[
StructLayout
(
LayoutKind
.
Sequential
)]
public
struct
OfflineModelConfig
{
...
...
@@ -44,6 +43,4 @@ namespace SherpaOnnx
[
MarshalAs
(
UnmanagedType
.
LPStr
)]
public
string
ModelType
;
}
}
...
...
scripts/dotnet/OfflineNemoEncDecCtcModelConfig.cs
查看文件 @
a99c7cb
...
...
@@ -8,7 +8,6 @@ using System;
namespace
SherpaOnnx
{
[
StructLayout
(
LayoutKind
.
Sequential
)]
public
struct
OfflineNemoEncDecCtcModelConfig
{
...
...
scripts/dotnet/OfflineParaformerModelConfig.cs
查看文件 @
a99c7cb
...
...
@@ -18,5 +18,4 @@ namespace SherpaOnnx
[
MarshalAs
(
UnmanagedType
.
LPStr
)]
public
string
Model
;
}
}
...
...
scripts/dotnet/OfflinePunctuation.cs
0 → 100644
查看文件 @
a99c7cb
/// Copyright (c) 2024 Xiaomi Corporation (authors: Fangjun Kuang)
using
System.Linq
;
using
System.Collections.Generic
;
using
System.Runtime.InteropServices
;
using
System.Text
;
using
System
;
namespace
SherpaOnnx
{
public
class
OfflinePunctuation
:
IDisposable
{
public
OfflinePunctuation
(
OfflinePunctuationConfig
config
)
{
IntPtr
h
=
SherpaOnnxCreateOfflinePunctuation
(
ref
config
);
_handle
=
new
HandleRef
(
this
,
h
);
}
public
String
AddPunct
(
String
text
)
{
IntPtr
p
=
SherpaOfflinePunctuationAddPunct
(
_handle
.
Handle
,
text
);
string
s
=
""
;
int
length
=
0
;
unsafe
{
byte
*
b
=
(
byte
*)
p
;
if
(
b
!=
null
)
{
while
(*
b
!=
0
)
{
++
b
;
length
+=
1
;
}
}
}
if
(
length
>
0
)
{
byte
[]
stringBuffer
=
new
byte
[
length
];
Marshal
.
Copy
(
p
,
stringBuffer
,
0
,
length
);
s
=
Encoding
.
UTF8
.
GetString
(
stringBuffer
);
}
SherpaOfflinePunctuationFreeText
(
p
);
return
s
;
}
public
void
Dispose
()
{
Cleanup
();
// Prevent the object from being placed on the
// finalization queue
System
.
GC
.
SuppressFinalize
(
this
);
}
~
OfflinePunctuation
()
{
Cleanup
();
}
private
void
Cleanup
()
{
SherpaOnnxDestroyOfflinePunctuation
(
_handle
.
Handle
);
// Don't permit the handle to be used again.
_handle
=
new
HandleRef
(
this
,
IntPtr
.
Zero
);
}
private
HandleRef
_handle
;
[
DllImport
(
Dll
.
Filename
)]
private
static
extern
IntPtr
SherpaOnnxCreateOfflinePunctuation
(
ref
OfflinePunctuationConfig
config
);
[
DllImport
(
Dll
.
Filename
)]
private
static
extern
void
SherpaOnnxDestroyOfflinePunctuation
(
IntPtr
handle
);
[
DllImport
(
Dll
.
Filename
)]
private
static
extern
IntPtr
SherpaOfflinePunctuationAddPunct
(
IntPtr
handle
,
[
MarshalAs
(
UnmanagedType
.
LPStr
)]
string
text
);
[
DllImport
(
Dll
.
Filename
)]
private
static
extern
void
SherpaOfflinePunctuationFreeText
(
IntPtr
p
);
}
}
...
...
scripts/dotnet/OfflinePunctuationConfig.cs
0 → 100644
查看文件 @
a99c7cb
/// Copyright (c) 2024 Xiaomi Corporation (authors: Fangjun Kuang)
using
System.Linq
;
using
System.Collections.Generic
;
using
System.Runtime.InteropServices
;
using
System.Text
;
using
System
;
namespace
SherpaOnnx
{
[
StructLayout
(
LayoutKind
.
Sequential
)]
public
struct
OfflinePunctuationConfig
{
public
OfflinePunctuationConfig
()
{
Model
=
new
OfflinePunctuationModelConfig
();
}
public
OfflinePunctuationModelConfig
Model
;
}
}
...
...
scripts/dotnet/OfflinePunctuationModelConfig.cs
0 → 100644
查看文件 @
a99c7cb
/// Copyright (c) 2024 Xiaomi Corporation (authors: Fangjun Kuang)
using
System.Linq
;
using
System.Collections.Generic
;
using
System.Runtime.InteropServices
;
using
System.Text
;
using
System
;
namespace
SherpaOnnx
{
[
StructLayout
(
LayoutKind
.
Sequential
)]
public
struct
OfflinePunctuationModelConfig
{
public
OfflinePunctuationModelConfig
()
{
CtTransformer
=
""
;
NumThreads
=
1
;
Debug
=
0
;
Provider
=
"cpu"
;
}
[
MarshalAs
(
UnmanagedType
.
LPStr
)]
public
string
CtTransformer
;
public
int
NumThreads
;
public
int
Debug
;
[
MarshalAs
(
UnmanagedType
.
LPStr
)]
public
string
Provider
;
}
}
...
...
scripts/dotnet/OfflineRecognizer.cs
查看文件 @
a99c7cb
...
...
@@ -72,5 +72,4 @@ namespace SherpaOnnx
[
DllImport
(
Dll
.
Filename
,
EntryPoint
=
"DecodeMultipleOfflineStreams"
)]
private
static
extern
void
Decode
(
IntPtr
handle
,
IntPtr
[]
streams
,
int
n
);
}
}
...
...
scripts/dotnet/OfflineRecognizerConfig.cs
查看文件 @
a99c7cb
...
...
@@ -8,7 +8,6 @@ using System;
namespace
SherpaOnnx
{
[
StructLayout
(
LayoutKind
.
Sequential
)]
public
struct
OfflineRecognizerConfig
{
...
...
@@ -38,6 +37,4 @@ namespace SherpaOnnx
public
float
HotwordsScore
;
}
}
...
...
scripts/dotnet/OfflineRecognizerResult.cs
查看文件 @
a99c7cb
...
...
@@ -8,7 +8,6 @@ using System;
namespace
SherpaOnnx
{
public
class
OfflineRecognizerResult
{
public
OfflineRecognizerResult
(
IntPtr
handle
)
...
...
@@ -44,6 +43,4 @@ namespace SherpaOnnx
private
String
_text
;
public
String
Text
=>
_text
;
}
}
...
...
scripts/dotnet/OfflineStream.cs
查看文件 @
a99c7cb
...
...
@@ -8,7 +8,6 @@ using System;
namespace
SherpaOnnx
{
public
class
OfflineStream
:
IDisposable
{
public
OfflineStream
(
IntPtr
p
)
...
...
@@ -68,5 +67,4 @@ namespace SherpaOnnx
[
DllImport
(
Dll
.
Filename
,
EntryPoint
=
"DestroyOfflineRecognizerResult"
)]
private
static
extern
void
DestroyResult
(
IntPtr
handle
);
}
}
...
...
scripts/dotnet/OfflineTdnnModelConfig.cs
查看文件 @
a99c7cb
...
...
@@ -18,5 +18,4 @@ namespace SherpaOnnx
[
MarshalAs
(
UnmanagedType
.
LPStr
)]
public
string
Model
;
}
}
...
...
scripts/dotnet/OfflineTransducerModelConfig.cs
查看文件 @
a99c7cb
...
...
@@ -26,5 +26,4 @@ namespace SherpaOnnx
[
MarshalAs
(
UnmanagedType
.
LPStr
)]
public
string
Joiner
;
}
}
...
...
scripts/dotnet/OfflineTtsConfig.cs
查看文件 @
a99c7cb
...
...
@@ -28,5 +28,4 @@ namespace SherpaOnnx
[
MarshalAs
(
UnmanagedType
.
LPStr
)]
public
string
RuleFars
;
}
}
...
...
scripts/dotnet/OfflineTtsModelConfig.cs
查看文件 @
a99c7cb
...
...
@@ -8,7 +8,6 @@ using System;
namespace
SherpaOnnx
{
[
StructLayout
(
LayoutKind
.
Sequential
)]
public
struct
OfflineTtsModelConfig
{
...
...
scripts/dotnet/OfflineWhisperModelConfig.cs
查看文件 @
a99c7cb
...
...
@@ -33,5 +33,4 @@ namespace SherpaOnnx
public
int
TailPaddings
;
}
}
...
...
scripts/dotnet/OnlineCtcFstDecoderConfig.cs
查看文件 @
a99c7cb
...
...
@@ -24,5 +24,4 @@ namespace SherpaOnnx
public
int
MaxActive
;
}
}
...
...
scripts/dotnet/OnlineModelConfig.cs
查看文件 @
a99c7cb
...
...
@@ -10,7 +10,6 @@ using System;
namespace
SherpaOnnx
{
[
StructLayout
(
LayoutKind
.
Sequential
)]
public
struct
OnlineModelConfig
{
...
...
@@ -45,5 +44,4 @@ namespace SherpaOnnx
[
MarshalAs
(
UnmanagedType
.
LPStr
)]
public
string
ModelType
;
}
}
...
...
scripts/dotnet/OnlineParaformerModelConfig.cs
查看文件 @
a99c7cb
...
...
@@ -10,7 +10,6 @@ using System;
namespace
SherpaOnnx
{
[
StructLayout
(
LayoutKind
.
Sequential
)]
public
struct
OnlineParaformerModelConfig
{
...
...
@@ -26,5 +25,4 @@ namespace SherpaOnnx
[
MarshalAs
(
UnmanagedType
.
LPStr
)]
public
string
Decoder
;
}
}
...
...
scripts/dotnet/OnlineRecognizerConfig.cs
查看文件 @
a99c7cb
...
...
@@ -10,7 +10,6 @@ using System;
namespace
SherpaOnnx
{
[
StructLayout
(
LayoutKind
.
Sequential
)]
public
struct
OnlineRecognizerConfig
{
...
...
@@ -66,5 +65,4 @@ namespace SherpaOnnx
public
OnlineCtcFstDecoderConfig
CtcFstDecoderConfig
;
}
}
...
...
scripts/dotnet/OnlineRecognizerResult.cs
查看文件 @
a99c7cb
...
...
@@ -10,7 +10,6 @@ using System;
namespace
SherpaOnnx
{
public
class
OnlineRecognizerResult
{
public
OnlineRecognizerResult
(
IntPtr
handle
)
...
...
scripts/dotnet/OnlineStream.cs
查看文件 @
a99c7cb
...
...
@@ -10,7 +10,6 @@ using System;
namespace
SherpaOnnx
{
public
class
OnlineStream
:
IDisposable
{
public
OnlineStream
(
IntPtr
p
)
...
...
@@ -61,5 +60,4 @@ namespace SherpaOnnx
[
DllImport
(
Dll
.
Filename
)]
private
static
extern
void
InputFinished
(
IntPtr
handle
);
}
}
...
...
scripts/dotnet/OnlineTransducerModelConfig.cs
查看文件 @
a99c7cb
...
...
@@ -10,7 +10,6 @@ using System;
namespace
SherpaOnnx
{
[
StructLayout
(
LayoutKind
.
Sequential
)]
public
struct
OnlineTransducerModelConfig
{
...
...
@@ -30,5 +29,4 @@ namespace SherpaOnnx
[
MarshalAs
(
UnmanagedType
.
LPStr
)]
public
string
Joiner
;
}
}
...
...
scripts/dotnet/examples/offline-punctuation.csproj
0 → 100644
查看文件 @
a99c7cb
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<RootNamespace>offline_punctuation</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<PropertyGroup>
<RestoreSources>/tmp/packages;$(RestoreSources);https://api.nuget.org/v3/index.json</RestoreSources>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="org.k2fsa.sherpa.onnx" Version="*" />
</ItemGroup>
</Project>
...
...
请
注册
或
登录
后发表评论