├── AliParaformerAsr.Tests ├── TestResources │ └── README.md ├── OfflineRecognizerTests .cs ├── README.md ├── AliParaformerAsr.Tests.csproj └── Utils │ └── TextHelper.cs ├── AliParaformerAsr ├── data │ └── embed.onnx ├── Model │ ├── PreEncoderConfEntity.cs │ ├── PostEncoderConfEntity.cs │ ├── OfflineInputEntity.cs │ ├── OnlineInputEntity.cs │ ├── CmvnEntity.cs │ ├── DecoderOutputEntity.cs │ ├── PredictorOutputEntity.cs │ ├── EncoderOutputEntity.cs │ ├── ModelOutputEntity.cs │ ├── OfflineOutputEntity.cs │ ├── OnlineOutputEntity.cs │ ├── OnlineRecognizerResultEntity.cs │ ├── OfflineRecognizerResultEntity.cs │ ├── PredictorConfEntity.cs │ ├── FrontendConfEntity.cs │ ├── ModelConfEntity.cs │ ├── DecoderConfEntity.cs │ ├── EncoderConfEntity.cs │ ├── ConfEntity.cs │ └── OfflineYamlEntity.cs ├── IOfflineProj.cs ├── Utils │ ├── PadHelper.cs │ └── PreloadHelper.cs ├── EmbedSVModel.cs ├── AliParaformerAsr.csproj ├── OfflineStream.cs ├── OfflineModel.cs ├── OfflineProjOfParaformer.cs ├── EmbedSeacoModel.cs ├── WavFrontend.cs ├── OfflineProjOfSeacoParaformer.cs ├── OnlineWavFrontend.cs ├── OfflineProjOfSenseVoiceSmall.cs └── OnlineModel.cs ├── AliParaformerAsr.Examples.MauiApp ├── Resources │ ├── Fonts │ │ ├── OpenSans-Regular.ttf │ │ └── OpenSans-Semibold.ttf │ ├── AppIcon │ │ └── appicon.svg │ ├── Raw │ │ └── AboutAssets.txt │ ├── Splash │ │ └── splash.svg │ ├── Styles │ │ └── Colors.xaml │ └── Images │ │ └── dotnet_bot.svg ├── AppShell.xaml.cs ├── Properties │ └── launchSettings.json ├── Platforms │ ├── Android │ │ ├── Resources │ │ │ └── values │ │ │ │ └── colors.xml │ │ ├── MainActivity.cs │ │ ├── AndroidManifest.xml │ │ └── MainApplication.cs │ ├── iOS │ │ ├── AppDelegate.cs │ │ ├── Program.cs │ │ └── Info.plist │ ├── MacCatalyst │ │ ├── AppDelegate.cs │ │ ├── Program.cs │ │ └── Info.plist │ ├── Windows │ │ ├── App.xaml │ │ ├── app.manifest │ │ ├── App.xaml.cs │ │ └── Package.appxmanifest │ └── Tizen │ │ ├── Main.cs │ │ └── tizen-manifest.xml ├── App.xaml.cs ├── MauiProgram.cs ├── MainPage.xaml.cs ├── MySplashPage.xaml.cs ├── Utils │ ├── SysConf.cs │ └── AEDEmojiHelper.cs ├── App.xaml ├── AppShell.xaml ├── MainPage.xaml ├── MySplashPage.xaml ├── RecognitionForFiles.xaml └── MauiApp1.csproj ├── AliParaformerAsr.Examples ├── BaseAsr.cs ├── app.manifest ├── AliParaformerAsr.Examples.csproj ├── Config │ └── TrimmerRoots.xml ├── Utils │ └── TextHelper.cs └── OfflineAliParaformerAsrRecognizer.cs ├── .gitattributes ├── AliParaformerAsr.sln ├── .gitignore ├── README.md └── LICENSE /AliParaformerAsr.Tests/TestResources/README.md: -------------------------------------------------------------------------------- 1 | 1.将模型放置在当前目录,并设置文件属性为“如果较新则复制” 2 | -------------------------------------------------------------------------------- /AliParaformerAsr/data/embed.onnx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/manyeyes/AliParaformerAsr/HEAD/AliParaformerAsr/data/embed.onnx -------------------------------------------------------------------------------- /AliParaformerAsr.Tests/OfflineRecognizerTests .cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/manyeyes/AliParaformerAsr/HEAD/AliParaformerAsr.Tests/OfflineRecognizerTests .cs -------------------------------------------------------------------------------- /AliParaformerAsr.Tests/README.md: -------------------------------------------------------------------------------- 1 | 1.下载模型: 2 | https://modelscope.cn/models/manyeyes/sensevoice-small-int8-onnx 3 | 4 | 2.将模型放入 TestResources 目录,并设置模型文件属性为“如果较新则复制” 5 | 6 | 3.运行测试 -------------------------------------------------------------------------------- /AliParaformerAsr.Examples.MauiApp/Resources/Fonts/OpenSans-Regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/manyeyes/AliParaformerAsr/HEAD/AliParaformerAsr.Examples.MauiApp/Resources/Fonts/OpenSans-Regular.ttf -------------------------------------------------------------------------------- /AliParaformerAsr.Examples.MauiApp/Resources/Fonts/OpenSans-Semibold.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/manyeyes/AliParaformerAsr/HEAD/AliParaformerAsr.Examples.MauiApp/Resources/Fonts/OpenSans-Semibold.ttf -------------------------------------------------------------------------------- /AliParaformerAsr.Examples.MauiApp/AppShell.xaml.cs: -------------------------------------------------------------------------------- 1 | namespace MauiApp1; 2 | 3 | public partial class AppShell : Shell 4 | { 5 | public AppShell() 6 | { 7 | InitializeComponent(); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /AliParaformerAsr.Examples.MauiApp/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "profiles": { 3 | "Windows Machine": { 4 | "commandName": "MsixPackage", 5 | "nativeDebugging": false 6 | } 7 | } 8 | } -------------------------------------------------------------------------------- /AliParaformerAsr.Examples.MauiApp/Resources/AppIcon/appicon.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /AliParaformerAsr.Examples.MauiApp/Platforms/Android/Resources/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #512BD4 4 | #2B0B98 5 | #2B0B98 6 | -------------------------------------------------------------------------------- /AliParaformerAsr.Examples.MauiApp/Platforms/iOS/AppDelegate.cs: -------------------------------------------------------------------------------- 1 | using Foundation; 2 | 3 | namespace MauiApp1; 4 | 5 | [Register("AppDelegate")] 6 | public class AppDelegate : MauiUIApplicationDelegate 7 | { 8 | protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp(); 9 | } 10 | -------------------------------------------------------------------------------- /AliParaformerAsr.Examples.MauiApp/Platforms/MacCatalyst/AppDelegate.cs: -------------------------------------------------------------------------------- 1 | using Foundation; 2 | 3 | namespace MauiApp1; 4 | 5 | [Register("AppDelegate")] 6 | public class AppDelegate : MauiUIApplicationDelegate 7 | { 8 | protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp(); 9 | } 10 | -------------------------------------------------------------------------------- /AliParaformerAsr.Examples/BaseAsr.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace AliParaformerAsr.Examples 8 | { 9 | internal class BaseAsr 10 | { 11 | public static string applicationBase = AppDomain.CurrentDomain.BaseDirectory; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /AliParaformerAsr.Examples.MauiApp/Platforms/Windows/App.xaml: -------------------------------------------------------------------------------- 1 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /AliParaformerAsr/Model/PreEncoderConfEntity.cs: -------------------------------------------------------------------------------- 1 | // See https://github.com/manyeyes for more information 2 | // Copyright (c) 2023 by manyeyes 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Text; 7 | using System.Threading.Tasks; 8 | 9 | namespace AliParaformerAsr.Model 10 | { 11 | public class PreEncoderConfEntity 12 | { 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /AliParaformerAsr/Model/PostEncoderConfEntity.cs: -------------------------------------------------------------------------------- 1 | // See https://github.com/manyeyes for more information 2 | // Copyright (c) 2023 by manyeyes 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Text; 7 | using System.Threading.Tasks; 8 | 9 | namespace AliParaformerAsr.Model 10 | { 11 | public class PostEncoderConfEntity 12 | { 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /AliParaformerAsr.Examples.MauiApp/Platforms/Tizen/Main.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Microsoft.Maui; 3 | using Microsoft.Maui.Hosting; 4 | 5 | namespace MauiApp1; 6 | 7 | class Program : MauiApplication 8 | { 9 | protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp(); 10 | 11 | static void Main(string[] args) 12 | { 13 | var app = new Program(); 14 | app.Run(args); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /AliParaformerAsr/Model/OfflineInputEntity.cs: -------------------------------------------------------------------------------- 1 | // See https://github.com/manyeyes for more information 2 | // Copyright (c) 2023 by manyeyes 3 | namespace AliParaformerAsr.Model 4 | { 5 | public class OfflineInputEntity 6 | { 7 | public float[]? Speech { get; set; } 8 | public int SpeechLength { get; set; } 9 | public List? Hotwords { get; set; } = new List(); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /AliParaformerAsr.Examples.MauiApp/Platforms/iOS/Program.cs: -------------------------------------------------------------------------------- 1 | using ObjCRuntime; 2 | using UIKit; 3 | 4 | namespace MauiApp1; 5 | 6 | public class Program 7 | { 8 | // This is the main entry point of the application. 9 | static void Main(string[] args) 10 | { 11 | // if you want to use a different Application Delegate class from "AppDelegate" 12 | // you can specify it here. 13 | UIApplication.Main(args, null, typeof(AppDelegate)); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /AliParaformerAsr.Examples.MauiApp/Platforms/MacCatalyst/Program.cs: -------------------------------------------------------------------------------- 1 | using ObjCRuntime; 2 | using UIKit; 3 | 4 | namespace MauiApp1; 5 | 6 | public class Program 7 | { 8 | // This is the main entry point of the application. 9 | static void Main(string[] args) 10 | { 11 | // if you want to use a different Application Delegate class from "AppDelegate" 12 | // you can specify it here. 13 | UIApplication.Main(args, null, typeof(AppDelegate)); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /AliParaformerAsr.Examples.MauiApp/App.xaml.cs: -------------------------------------------------------------------------------- 1 | namespace MauiApp1; 2 | 3 | public partial class App : Application 4 | { 5 | public App() 6 | { 7 | InitializeComponent(); 8 | MainPage = new MySplashPage(); 9 | _ = EndSplash(); 10 | } 11 | async Task EndSplash() 12 | { 13 | await Task.Delay(1000); 14 | MainThread.BeginInvokeOnMainThread(() => 15 | { 16 | MainPage = new AppShell(); 17 | }); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /AliParaformerAsr.Examples.MauiApp/MauiProgram.cs: -------------------------------------------------------------------------------- 1 | namespace MauiApp1; 2 | 3 | public static class MauiProgram 4 | { 5 | public static MauiApp CreateMauiApp() 6 | { 7 | var builder = MauiApp.CreateBuilder(); 8 | builder 9 | .UseMauiApp() 10 | .ConfigureFonts(fonts => 11 | { 12 | fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular"); 13 | fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold"); 14 | }); 15 | 16 | return builder.Build(); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /AliParaformerAsr.Examples.MauiApp/Platforms/Android/MainActivity.cs: -------------------------------------------------------------------------------- 1 | using Android.App; 2 | using Android.Content.PM; 3 | using Android.OS; 4 | 5 | namespace MauiApp1; 6 | 7 | [Activity(Theme = "@style/Maui.SplashTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation | ConfigChanges.UiMode | ConfigChanges.ScreenLayout | ConfigChanges.SmallestScreenSize | ConfigChanges.Density)] 8 | public class MainActivity : MauiAppCompatActivity 9 | { 10 | } 11 | -------------------------------------------------------------------------------- /AliParaformerAsr/Model/OnlineInputEntity.cs: -------------------------------------------------------------------------------- 1 | // See https://github.com/manyeyes for more information 2 | // Copyright (c) 2023 by manyeyes 3 | namespace AliParaformerAsr.Model 4 | { 5 | public class OnlineInputEntity 6 | { 7 | private float[]? _speech; 8 | private int _speech_length; 9 | public float[]? Speech { get => _speech; set => _speech = value; } 10 | public int SpeechLength { get => _speech_length; set => _speech_length = value; } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /AliParaformerAsr/Model/CmvnEntity.cs: -------------------------------------------------------------------------------- 1 | // See https://github.com/manyeyes for more information 2 | // Copyright (c) 2023 by manyeyes 3 | namespace AliParaformerAsr.Model 4 | { 5 | internal class CmvnEntity 6 | { 7 | private List _means = new List(); 8 | private List _vars = new List(); 9 | 10 | public List Means { get => _means; set => _means = value; } 11 | public List Vars { get => _vars; set => _vars = value; } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /AliParaformerAsr.Examples/app.manifest: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /AliParaformerAsr.Examples.MauiApp/MainPage.xaml.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Maui.Storage; 2 | using NAudio.Wave; 3 | using System.ComponentModel; 4 | using System.Net; 5 | using System.Reflection; 6 | using System.Text; 7 | using System.Windows.Input; 8 | using static System.Net.Mime.MediaTypeNames; 9 | using MauiApp1.Utils; 10 | using System; 11 | using Microsoft.Maui.Graphics; 12 | 13 | namespace MauiApp1; 14 | 15 | public partial class MainPage : ContentPage 16 | { 17 | 18 | public MainPage() 19 | { 20 | InitializeComponent(); 21 | } 22 | 23 | 24 | } 25 | 26 | -------------------------------------------------------------------------------- /AliParaformerAsr.Examples.MauiApp/MySplashPage.xaml.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Maui.Storage; 2 | using NAudio.Wave; 3 | using System.ComponentModel; 4 | using System.Net; 5 | using System.Reflection; 6 | using System.Text; 7 | using System.Windows.Input; 8 | using static System.Net.Mime.MediaTypeNames; 9 | using MauiApp1.Utils; 10 | using System; 11 | using Microsoft.Maui.Graphics; 12 | 13 | namespace MauiApp1; 14 | 15 | public partial class MySplashPage : ContentPage 16 | { 17 | 18 | public MySplashPage() 19 | { 20 | InitializeComponent(); 21 | } 22 | 23 | 24 | } 25 | 26 | -------------------------------------------------------------------------------- /AliParaformerAsr/Model/DecoderOutputEntity.cs: -------------------------------------------------------------------------------- 1 | // See https://github.com/manyeyes for more information 2 | // Copyright (c) 2023 by manyeyes 3 | 4 | namespace AliParaformerAsr.Model 5 | { 6 | public class DecoderOutputEntity 7 | { 8 | private float[]? _logits; 9 | private List? _sample_ids; 10 | private List statesList; 11 | 12 | public float[]? Logits { get => _logits; set => _logits = value; } 13 | public List? Sample_ids { get => _sample_ids; set => _sample_ids = value; } 14 | public List StatesList { get => statesList; set => statesList = value; } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /AliParaformerAsr.Examples.MauiApp/Utils/SysConf.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace MauiApp1.Utils 8 | { 9 | internal class SysConf 10 | { 11 | #if WINDOWS 12 | private static string _applicationBase = Microsoft.Maui.Storage.FileSystem.AppDataDirectory; 13 | #else 14 | private static string _applicationBase = AppDomain.CurrentDomain.BaseDirectory; 15 | #endif 16 | public SysConf() { } 17 | 18 | public static string ApplicationBase { get => _applicationBase; set => _applicationBase = value; } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /AliParaformerAsr/Model/PredictorOutputEntity.cs: -------------------------------------------------------------------------------- 1 | // See https://github.com/manyeyes for more information 2 | // Copyright (c) 2023 by manyeyes 3 | 4 | // See https://github.com/manyeyes for more information 5 | // Copyright (c) 2023 by manyeyes 6 | using System.Collections; 7 | 8 | namespace AliParaformerAsr.Model 9 | { 10 | public class PredictorOutputEntity 11 | { 12 | 13 | private float[] _acoustic_embeds; 14 | private int[] _acoustic_embeds_len; 15 | 16 | public float[] Acoustic_embeds { get => _acoustic_embeds; set => _acoustic_embeds = value; } 17 | public int[] Acoustic_embeds_len { get => _acoustic_embeds_len; set => _acoustic_embeds_len = value; } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /AliParaformerAsr.Examples.MauiApp/App.xaml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /AliParaformerAsr.Examples.MauiApp/AppShell.xaml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 13 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /AliParaformerAsr.Examples.MauiApp/Resources/Raw/AboutAssets.txt: -------------------------------------------------------------------------------- 1 | Any raw assets you want to be deployed with your application can be placed in 2 | this directory (and child directories). Deployment of the asset to your application 3 | is automatically handled by the following `MauiAsset` Build Action within your `.csproj`. 4 | 5 | 6 | 7 | These files will be deployed with you package and will be accessible using Essentials: 8 | 9 | async Task LoadMauiAsset() 10 | { 11 | using var stream = await FileSystem.OpenAppPackageFileAsync("AboutAssets.txt"); 12 | using var reader = new StreamReader(stream); 13 | 14 | var contents = reader.ReadToEnd(); 15 | } 16 | -------------------------------------------------------------------------------- /AliParaformerAsr/Model/EncoderOutputEntity.cs: -------------------------------------------------------------------------------- 1 | // See https://github.com/manyeyes for more information 2 | // Copyright (c) 2023 by manyeyes 3 | 4 | // See https://github.com/manyeyes for more information 5 | // Copyright (c) 2023 by manyeyes 6 | using System.Collections; 7 | 8 | namespace AliParaformerAsr.Model 9 | { 10 | public class EncoderOutputEntity 11 | { 12 | 13 | private List>? _enc; 14 | private int[]? _enc_len; 15 | private List>? _alphas; 16 | 17 | public List>? Enc { get => _enc; set => _enc = value; } 18 | public int[]? Enc_len { get => _enc_len; set => _enc_len = value; } 19 | public List>? Alphas { get => _alphas; set => _alphas = value; } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /AliParaformerAsr.Examples.MauiApp/MainPage.xaml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 11 | 12 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /AliParaformerAsr/Model/ModelOutputEntity.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.ML.OnnxRuntime.Tensors; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace AliParaformerAsr.Model 9 | { 10 | internal class ModelOutputEntity 11 | { 12 | private Tensor? _model_out; 13 | private int[]? _model_out_lens; 14 | private Tensor? _cif_peak_tensor; 15 | 16 | public Tensor? model_out { get => _model_out; set => _model_out = value; } 17 | public int[]? model_out_lens { get => _model_out_lens; set => _model_out_lens = value; } 18 | public Tensor? cif_peak_tensor { get => _cif_peak_tensor; set => _cif_peak_tensor = value; } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /AliParaformerAsr.Examples.MauiApp/MySplashPage.xaml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 11 | 12 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /AliParaformerAsr/Model/OfflineOutputEntity.cs: -------------------------------------------------------------------------------- 1 | // See https://github.com/manyeyes for more information 2 | // Copyright (c) 2023 by manyeyes 3 | namespace AliParaformerAsr.Model 4 | { 5 | public class OfflineOutputEntity 6 | { 7 | 8 | private float[]? logits; 9 | private long[]? _token_num; 10 | private List? _token_nums=new List() { new int[4]}; 11 | private int[] _token_nums_length; 12 | 13 | public float[]? Logits { get => logits; set => logits = value; } 14 | public long[]? Token_num { get => _token_num; set => _token_num = value; } 15 | public List? Token_nums { get => _token_nums; set => _token_nums = value; } 16 | public int[] Token_nums_length { get => _token_nums_length; set => _token_nums_length = value; } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /AliParaformerAsr/Model/OnlineOutputEntity.cs: -------------------------------------------------------------------------------- 1 | // See https://github.com/manyeyes for more information 2 | // Copyright (c) 2023 by manyeyes 3 | 4 | namespace AliParaformerAsr.Model 5 | { 6 | public class OnlineOutputEntity 7 | { 8 | 9 | private float[]? logits; 10 | private long[]? _token_num; 11 | private List? _token_nums=new List() { new int[4]}; 12 | private int[] _token_nums_length; 13 | 14 | public float[]? Logits { get => logits; set => logits = value; } 15 | public long[]? Token_num { get => _token_num; set => _token_num = value; } 16 | public List? Token_nums { get => _token_nums; set => _token_nums = value; } 17 | public int[] Token_nums_length { get => _token_nums_length; set => _token_nums_length = value; } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /AliParaformerAsr.Examples.MauiApp/Platforms/Windows/app.manifest: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 11 | true/PM 12 | PerMonitorV2, PerMonitor 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /AliParaformerAsr.Examples.MauiApp/Platforms/Tizen/tizen-manifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | maui-appicon-placeholder 7 | 8 | 9 | 10 | 11 | http://tizen.org/privilege/internet 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /AliParaformerAsr.Examples.MauiApp/Platforms/Windows/App.xaml.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.UI.Xaml; 2 | 3 | // To learn more about WinUI, the WinUI project structure, 4 | // and more about our project templates, see: http://aka.ms/winui-project-info. 5 | 6 | namespace MauiApp1.WinUI; 7 | 8 | /// 9 | /// Provides application-specific behavior to supplement the default Application class. 10 | /// 11 | public partial class App : MauiWinUIApplication 12 | { 13 | /// 14 | /// Initializes the singleton application object. This is the first line of authored code 15 | /// executed, and as such is the logical equivalent of main() or WinMain(). 16 | /// 17 | public App() 18 | { 19 | this.InitializeComponent(); 20 | } 21 | 22 | protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp(); 23 | } 24 | 25 | -------------------------------------------------------------------------------- /AliParaformerAsr/IOfflineProj.cs: -------------------------------------------------------------------------------- 1 | using AliParaformerAsr.Model; 2 | using Microsoft.ML.OnnxRuntime; 3 | 4 | namespace AliParaformerAsr 5 | { 6 | internal interface IOfflineProj 7 | { 8 | InferenceSession ModelSession 9 | { 10 | get; 11 | set; 12 | } 13 | int Blank_id 14 | { 15 | get; 16 | set; 17 | } 18 | int Sos_eos_id 19 | { 20 | get; 21 | set; 22 | } 23 | int Unk_id 24 | { 25 | get; 26 | set; 27 | } 28 | int SampleRate 29 | { 30 | get; 31 | set; 32 | } 33 | int FeatureDim 34 | { 35 | get; 36 | set; 37 | } 38 | internal ModelOutputEntity ModelProj(List modelInputs); 39 | internal void Dispose(); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /AliParaformerAsr.Examples/AliParaformerAsr.Examples.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net9.0 6 | enable 7 | 10 8 | enable 9 | false 10 | app.manifest 11 | 1.1.6 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /AliParaformerAsr/Model/OnlineRecognizerResultEntity.cs: -------------------------------------------------------------------------------- 1 | // See https://github.com/manyeyes for more information 2 | // Copyright (c) 2023 by manyeyes 3 | namespace AliParaformerAsr.Model 4 | { 5 | /// 6 | /// online recognizer result entity 7 | /// Copyright (c) 2023 by manyeyes 8 | /// 9 | public class OnlineRecognizerResultEntity 10 | { 11 | /// 12 | /// recognizer result 13 | /// 14 | public string? Text { get; set; } 15 | /// 16 | /// recognizer result length 17 | /// 18 | public int TextLen { get; set; } 19 | /// 20 | /// decode tokens 21 | /// 22 | public List? Tokens { get; set; } = new List(); 23 | 24 | /// 25 | /// timestamps 26 | /// 27 | public List? Timestamps { get; set; } = new List(); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /AliParaformerAsr/Model/OfflineRecognizerResultEntity.cs: -------------------------------------------------------------------------------- 1 | // See https://github.com/manyeyes for more information 2 | // Copyright (c) 2023 by manyeyes 3 | namespace AliParaformerAsr.Model 4 | { 5 | /// 6 | /// online recognizer result entity 7 | /// Copyright (c) 2023 by manyeyes 8 | /// 9 | public class OfflineRecognizerResultEntity 10 | { 11 | /// 12 | /// recognizer result 13 | /// 14 | public string? Text { get; set; } 15 | /// 16 | /// recognizer result length 17 | /// 18 | public int TextLen { get; set; } 19 | /// 20 | /// decode tokens 21 | /// 22 | public List? Tokens { get; set; } = new List(); 23 | 24 | /// 25 | /// timestamps 26 | /// 27 | public List? Timestamps { get; set; } = new List(); 28 | 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /AliParaformerAsr/Model/PredictorConfEntity.cs: -------------------------------------------------------------------------------- 1 | // See https://github.com/manyeyes for more information 2 | // Copyright (c) 2023 by manyeyes 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Text; 7 | using System.Threading.Tasks; 8 | 9 | namespace AliParaformerAsr.Model 10 | { 11 | public class PredictorConfEntity 12 | { 13 | private int _idim = 512; 14 | private float _threshold = 1.0F; 15 | private int _l_order = 1; 16 | private int _r_order = 1; 17 | private float _tail_threshold = 0.45F; 18 | 19 | public int idim { get => _idim; set => _idim = value; } 20 | public float threshold { get => _threshold; set => _threshold = value; } 21 | public int l_order { get => _l_order; set => _l_order = value; } 22 | public int r_order { get => _r_order; set => _r_order = value; } 23 | public float tail_threshold { get => _tail_threshold; set => _tail_threshold = value; } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /AliParaformerAsr.Examples.MauiApp/Platforms/MacCatalyst/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | UIDeviceFamily 6 | 7 | 1 8 | 2 9 | 10 | UIRequiredDeviceCapabilities 11 | 12 | arm64 13 | 14 | UISupportedInterfaceOrientations 15 | 16 | UIInterfaceOrientationPortrait 17 | UIInterfaceOrientationLandscapeLeft 18 | UIInterfaceOrientationLandscapeRight 19 | 20 | UISupportedInterfaceOrientations~ipad 21 | 22 | UIInterfaceOrientationPortrait 23 | UIInterfaceOrientationPortraitUpsideDown 24 | UIInterfaceOrientationLandscapeLeft 25 | UIInterfaceOrientationLandscapeRight 26 | 27 | XSAppIconAssets 28 | Assets.xcassets/appicon.appiconset 29 | 30 | 31 | -------------------------------------------------------------------------------- /AliParaformerAsr.Examples.MauiApp/Platforms/iOS/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | LSRequiresIPhoneOS 6 | 7 | UIDeviceFamily 8 | 9 | 1 10 | 2 11 | 12 | UIRequiredDeviceCapabilities 13 | 14 | arm64 15 | 16 | UISupportedInterfaceOrientations 17 | 18 | UIInterfaceOrientationPortrait 19 | UIInterfaceOrientationLandscapeLeft 20 | UIInterfaceOrientationLandscapeRight 21 | 22 | UISupportedInterfaceOrientations~ipad 23 | 24 | UIInterfaceOrientationPortrait 25 | UIInterfaceOrientationPortraitUpsideDown 26 | UIInterfaceOrientationLandscapeLeft 27 | UIInterfaceOrientationLandscapeRight 28 | 29 | XSAppIconAssets 30 | Assets.xcassets/appicon.appiconset 31 | 32 | 33 | -------------------------------------------------------------------------------- /AliParaformerAsr/Model/FrontendConfEntity.cs: -------------------------------------------------------------------------------- 1 | // See https://github.com/manyeyes for more information 2 | // Copyright (c) 2023 by manyeyes 3 | namespace AliParaformerAsr.Model 4 | { 5 | public class FrontendConfEntity 6 | { 7 | private int _fs = 16000; 8 | private string _window = "hamming"; 9 | private int _n_mels = 80; 10 | private int _frame_length = 25; 11 | private int _frame_shift = 10; 12 | private float _dither = 1.0F; 13 | private int _lfr_m = 7; 14 | private int _lfr_n = 6; 15 | private bool _snip_edges = false; 16 | 17 | public int fs { get => _fs; set => _fs = value; } 18 | public string window { get => _window; set => _window = value; } 19 | public int n_mels { get => _n_mels; set => _n_mels = value; } 20 | public int frame_length { get => _frame_length; set => _frame_length = value; } 21 | public int frame_shift { get => _frame_shift; set => _frame_shift = value; } 22 | public float dither { get => _dither; set => _dither = value; } 23 | public int lfr_m { get => _lfr_m; set => _lfr_m = value; } 24 | public int lfr_n { get => _lfr_n; set => _lfr_n = value; } 25 | public bool snip_edges { get => _snip_edges; set => _snip_edges = value; } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /AliParaformerAsr.Examples.MauiApp/Platforms/Android/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /AliParaformerAsr.Tests/AliParaformerAsr.Tests.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net9.0 5 | enable 6 | enable 7 | 8 | false 9 | true 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /AliParaformerAsr/Model/ModelConfEntity.cs: -------------------------------------------------------------------------------- 1 | // See https://github.com/manyeyes for more information 2 | // Copyright (c) 2023 by manyeyes 3 | namespace AliParaformerAsr.Model 4 | { 5 | public class ModelConfEntity 6 | { 7 | private float _ctc_weight = 0.0F; 8 | private float _lsm_weight = 0.1F; 9 | private bool _length_normalized_loss = true; 10 | private float _predictor_weight = 1.0F; 11 | private int _predictor_bias = 1; 12 | private float _sampling_ratio = 0.75F; 13 | private int _sos = 1; 14 | private int _eos = 2; 15 | private int _ignore_id = -1; 16 | 17 | public float ctc_weight { get => _ctc_weight; set => _ctc_weight = value; } 18 | public float lsm_weight { get => _lsm_weight; set => _lsm_weight = value; } 19 | public bool length_normalized_loss { get => _length_normalized_loss; set => _length_normalized_loss = value; } 20 | public float predictor_weight { get => _predictor_weight; set => _predictor_weight = value; } 21 | public int predictor_bias { get => _predictor_bias; set => _predictor_bias = value; } 22 | public float sampling_ratio { get => _sampling_ratio; set => _sampling_ratio = value; } 23 | public int sos { get => _sos; set => _sos = value; } 24 | public int eos { get => _eos; set => _eos = value; } 25 | public int ignore_id { get => _ignore_id; set => _ignore_id = value; } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /AliParaformerAsr.Examples.MauiApp/Utils/AEDEmojiHelper.cs: -------------------------------------------------------------------------------- 1 | using System.Text.RegularExpressions; 2 | 3 | namespace MauiApp1.Utils 4 | { 5 | internal class AEDEmojiHelper 6 | { 7 | public static string ReplaceTagsWithEmojis(string input) 8 | { 9 | // 定义标签与表情包的映射关系 10 | var emojiMap = new System.Collections.Generic.Dictionary 11 | { 12 | { "Laughter", "😆" }, 13 | { "Applause", "👏" }, 14 | { "HAPPY", "😀" }, 15 | { "SAD", "😢" }, 16 | { "ANGRY", "😡" }, 17 | { "NEUTRAL", "😐" }, 18 | { "FEARFUL", "😨" }, 19 | { "DISGUSTED", "🤢" }, 20 | { "SURPRISED", "😲" }, 21 | { "Cry", "😭" }, 22 | { "Sneeze", "👃🤧" }, 23 | { "Cough", "🤒" }, 24 | { "Sing", "🎤" } 25 | }; 26 | 27 | string pattern = @"<\|(\w+)\|>"; 28 | return Regex.Replace(input, pattern, match => 29 | { 30 | string tag = match.Groups[1].Value; 31 | if (emojiMap.TryGetValue(tag, out string emoji)) 32 | { 33 | return emoji; 34 | } 35 | return ""; 36 | }); 37 | } 38 | 39 | public static string ReplaceTagsWithEmpty(string input) 40 | { 41 | string pattern = @"<\|.*?\|>"; 42 | return Regex.Replace(input, pattern, match => 43 | { 44 | return ""; 45 | }); 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /AliParaformerAsr.Examples/Config/TrimmerRoots.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /AliParaformerAsr/Model/DecoderConfEntity.cs: -------------------------------------------------------------------------------- 1 | // See https://github.com/manyeyes for more information 2 | // Copyright (c) 2023 by manyeyes 3 | namespace AliParaformerAsr.Model 4 | { 5 | public class DecoderConfEntity 6 | { 7 | private int _attention_heads = 4; 8 | private int _linear_units = 2048; 9 | private int _num_blocks = 16; 10 | private float _dropout_rate = 0.1F; 11 | private float _positional_dropout_rate = 0.1F; 12 | private float _self_attention_dropout_rate= 0.1F; 13 | private float _src_attention_dropout_rate = 0.1F; 14 | private int _att_layer_num = 16; 15 | private int _kernel_size = 11; 16 | private int _sanm_shfit = 0; 17 | 18 | public int attention_heads { get => _attention_heads; set => _attention_heads = value; } 19 | public int linear_units { get => _linear_units; set => _linear_units = value; } 20 | public int num_blocks { get => _num_blocks; set => _num_blocks = value; } 21 | public float dropout_rate { get => _dropout_rate; set => _dropout_rate = value; } 22 | public float positional_dropout_rate { get => _positional_dropout_rate; set => _positional_dropout_rate = value; } 23 | public float self_attention_dropout_rate { get => _self_attention_dropout_rate; set => _self_attention_dropout_rate = value; } 24 | public float src_attention_dropout_rate { get => _src_attention_dropout_rate; set => _src_attention_dropout_rate = value; } 25 | public int att_layer_num { get => _att_layer_num; set => _att_layer_num = value; } 26 | public int kernel_size { get => _kernel_size; set => _kernel_size = value; } 27 | public int sanm_shfit { get => _sanm_shfit; set => _sanm_shfit = value; } 28 | 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /AliParaformerAsr.Examples.MauiApp/Resources/Splash/splash.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /AliParaformerAsr.Tests/Utils/TextHelper.cs: -------------------------------------------------------------------------------- 1 | namespace AliParaformerAsr.Tests.Utils 2 | { 3 | internal class TextHelper 4 | { 5 | public static List? GetHotwords(string tokensFilePath, string hotwordFilePath) 6 | { 7 | List? hotwords = new List(); 8 | if (File.Exists(tokensFilePath) && File.Exists(hotwordFilePath)) 9 | { 10 | string[] tokens = File.ReadAllLines(tokensFilePath); 11 | string[] sentences = File.ReadAllLines(hotwordFilePath); 12 | foreach (string sentence in sentences) 13 | { 14 | string[] wordList = new string[] { sentence };//TODO:分词 15 | foreach (string word in wordList) 16 | { 17 | List ids = word.ToCharArray().Select(x => Array.IndexOf(tokens, x.ToString())).Where(x => x != -1).ToList(); 18 | hotwords.Add(ids.ToArray()); 19 | } 20 | } 21 | hotwords.Add(new int[] { 1 }); 22 | } 23 | return hotwords; 24 | } 25 | public static List? GetHotwords(string tokensFilePath, string[] wordList) 26 | { 27 | List? hotwords = new List(); 28 | if (File.Exists(tokensFilePath) && wordList.Length>0) 29 | { 30 | string[] tokens = File.ReadAllLines(tokensFilePath); 31 | foreach (string word in wordList) 32 | { 33 | List ids = word.ToCharArray().Select(x => Array.IndexOf(tokens, x.ToString())).Where(x => x != -1).ToList(); 34 | hotwords.Add(ids.ToArray()); 35 | } 36 | hotwords.Add(new int[] { 1 }); 37 | } 38 | return hotwords; 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /AliParaformerAsr.Examples.MauiApp/Platforms/Android/MainApplication.cs: -------------------------------------------------------------------------------- 1 | using Android.App; 2 | using Android.Runtime; 3 | 4 | namespace MauiApp1; 5 | 6 | [Application] 7 | 8 | //[assembly: UsesPermission(Android.Manifest.Permission.ReadExternalStorage, MaxSDKVersion = 32)] 9 | [assembly: UsesPermission(Android.Manifest.Permission.ReadMediaAudio)] 10 | [assembly: UsesPermission(Android.Manifest.Permission.ReadMediaImages)] 11 | [assembly: UsesPermission(Android.Manifest.Permission.ReadMediaVideo)] 12 | [assembly: UsesPermission(Android.Manifest.Permission.ManageExternalStorage)] 13 | // Needed for Picking photo/video 14 | [assembly: UsesPermission(Android.Manifest.Permission.ReadExternalStorage)] 15 | 16 | // Needed for Taking photo/video 17 | [assembly: UsesPermission(Android.Manifest.Permission.WriteExternalStorage)] 18 | [assembly: UsesPermission(Android.Manifest.Permission.Camera)] 19 | [assembly: UsesPermission(Android.Manifest.Permission.RecordAudio)] 20 | [assembly: UsesPermission(Android.Manifest.Permission.CaptureVideoOutput)] 21 | 22 | // Add these properties if you would like to filter out devices that do not have cameras, or set to false to make them optional 23 | [assembly: UsesFeature("android.hardware.camera", Required = true)] 24 | [assembly: UsesFeature("android.hardware.camera.autofocus", Required = true)] 25 | [assembly: UsesFeature("android.hardware.recordaudio", Required = true)] 26 | [assembly: UsesFeature("android.hardware.recordaudio.autofocus", Required = true)] 27 | [assembly: UsesFeature("android.hardware.capturevideooutput", Required = true)] 28 | [assembly: UsesFeature("android.hardware.capturevideooutput.autofocus", Required = true)] 29 | 30 | 31 | public class MainApplication : MauiApplication 32 | { 33 | public MainApplication(IntPtr handle, JniHandleOwnership ownership) 34 | : base(handle, ownership) 35 | { 36 | } 37 | 38 | protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp(); 39 | } 40 | -------------------------------------------------------------------------------- /AliParaformerAsr.Examples/Utils/TextHelper.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace AliParaformerAsr.Examples.Utils 8 | { 9 | internal class TextHelper 10 | { 11 | public static List? GetHotwords(string tokensFilePath, string hotwordFilePath) 12 | { 13 | List? hotwords = new List(); 14 | if (File.Exists(tokensFilePath) && File.Exists(hotwordFilePath)) 15 | { 16 | string[] tokens = File.ReadAllLines(tokensFilePath); 17 | string[] sentences = File.ReadAllLines(hotwordFilePath); 18 | foreach (string sentence in sentences) 19 | { 20 | string[] wordList = new string[] { sentence };//TODO:分词 21 | foreach (string word in wordList) 22 | { 23 | List ids = word.ToCharArray().Select(x => Array.IndexOf(tokens, x.ToString())).Where(x => x != -1).ToList(); 24 | hotwords.Add(ids.ToArray()); 25 | } 26 | } 27 | hotwords.Add(new int[] { 1 }); 28 | } 29 | return hotwords; 30 | } 31 | public static List? GetHotwords(string tokensFilePath, string[] wordList) 32 | { 33 | List? hotwords = new List(); 34 | if (File.Exists(tokensFilePath) && wordList.Length>0) 35 | { 36 | string[] tokens = File.ReadAllLines(tokensFilePath); 37 | foreach (string word in wordList) 38 | { 39 | List ids = word.ToCharArray().Select(x => Array.IndexOf(tokens, x.ToString())).Where(x => x != -1).ToList(); 40 | hotwords.Add(ids.ToArray()); 41 | } 42 | hotwords.Add(new int[] { 1 }); 43 | } 44 | return hotwords; 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /AliParaformerAsr.Examples.MauiApp/Platforms/Windows/Package.appxmanifest: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | $placeholder$ 15 | User Name 16 | $placeholder$.png 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /AliParaformerAsr/Model/EncoderConfEntity.cs: -------------------------------------------------------------------------------- 1 | // See https://github.com/manyeyes for more information 2 | // Copyright (c) 2023 by manyeyes 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Text; 7 | using System.Threading.Tasks; 8 | 9 | namespace AliParaformerAsr.Model 10 | { 11 | public class EncoderConfEntity 12 | { 13 | private int _output_size = 512; 14 | private int _attention_heads = 4; 15 | private int _linear_units = 2048; 16 | private int _num_blocks = 50; 17 | private float _dropout_rate = 0.1F; 18 | private float _positional_dropout_rate = 0.1F; 19 | private float _attention_dropout_rate= 0.1F; 20 | private string _input_layer = "pe"; 21 | private string _pos_enc_class = "SinusoidalPositionEncoder"; 22 | private bool _normalize_before = true; 23 | private int _kernel_size = 11; 24 | private int _sanm_shfit = 0; 25 | private string _selfattention_layer_type = "sanm"; 26 | 27 | public int output_size { get => _output_size; set => _output_size = value; } 28 | public int attention_heads { get => _attention_heads; set => _attention_heads = value; } 29 | public int linear_units { get => _linear_units; set => _linear_units = value; } 30 | public int num_blocks { get => _num_blocks; set => _num_blocks = value; } 31 | public float dropout_rate { get => _dropout_rate; set => _dropout_rate = value; } 32 | public float positional_dropout_rate { get => _positional_dropout_rate; set => _positional_dropout_rate = value; } 33 | public float attention_dropout_rate { get => _attention_dropout_rate; set => _attention_dropout_rate = value; } 34 | public string input_layer { get => _input_layer; set => _input_layer = value; } 35 | public string pos_enc_class { get => _pos_enc_class; set => _pos_enc_class = value; } 36 | public bool normalize_before { get => _normalize_before; set => _normalize_before = value; } 37 | public int kernel_size { get => _kernel_size; set => _kernel_size = value; } 38 | public int sanm_shfit { get => _sanm_shfit; set => _sanm_shfit = value; } 39 | public string selfattention_layer_type { get => _selfattention_layer_type; set => _selfattention_layer_type = value; } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /AliParaformerAsr.Examples.MauiApp/Resources/Styles/Colors.xaml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | 7 | #512BD4 8 | #DFD8F7 9 | #2B0B98 10 | White 11 | Black 12 | #E1E1E1 13 | #C8C8C8 14 | #ACACAC 15 | #919191 16 | #6E6E6E 17 | #404040 18 | #212121 19 | #141414 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | #F7B548 35 | #FFD590 36 | #FFE5B9 37 | #28C2D1 38 | #7BDDEF 39 | #C3F2F4 40 | #3E8EED 41 | #72ACF1 42 | #A7CBF6 43 | 44 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Set default behavior to automatically normalize line endings. 3 | ############################################################################### 4 | * text=auto 5 | 6 | ############################################################################### 7 | # Set default behavior for command prompt diff. 8 | # 9 | # This is need for earlier builds of msysgit that does not have it on by 10 | # default for csharp files. 11 | # Note: This is only used by command line 12 | ############################################################################### 13 | #*.cs diff=csharp 14 | 15 | ############################################################################### 16 | # Set the merge driver for project and solution files 17 | # 18 | # Merging from the command prompt will add diff markers to the files if there 19 | # are conflicts (Merging from VS is not affected by the settings below, in VS 20 | # the diff markers are never inserted). Diff markers may cause the following 21 | # file extensions to fail to load in VS. An alternative would be to treat 22 | # these files as binary and thus will always conflict and require user 23 | # intervention with every merge. To do so, just uncomment the entries below 24 | ############################################################################### 25 | #*.sln merge=binary 26 | #*.csproj merge=binary 27 | #*.vbproj merge=binary 28 | #*.vcxproj merge=binary 29 | #*.vcproj merge=binary 30 | #*.dbproj merge=binary 31 | #*.fsproj merge=binary 32 | #*.lsproj merge=binary 33 | #*.wixproj merge=binary 34 | #*.modelproj merge=binary 35 | #*.sqlproj merge=binary 36 | #*.wwaproj merge=binary 37 | 38 | ############################################################################### 39 | # behavior for image files 40 | # 41 | # image files are treated as binary by default. 42 | ############################################################################### 43 | #*.jpg binary 44 | #*.png binary 45 | #*.gif binary 46 | 47 | ############################################################################### 48 | # diff behavior for common document formats 49 | # 50 | # Convert binary document formats to text before diffing them. This feature 51 | # is only available from the command line. Turn it on by uncommenting the 52 | # entries below. 53 | ############################################################################### 54 | #*.doc diff=astextplain 55 | #*.DOC diff=astextplain 56 | #*.docx diff=astextplain 57 | #*.DOCX diff=astextplain 58 | #*.dot diff=astextplain 59 | #*.DOT diff=astextplain 60 | #*.pdf diff=astextplain 61 | #*.PDF diff=astextplain 62 | #*.rtf diff=astextplain 63 | #*.RTF diff=astextplain 64 | -------------------------------------------------------------------------------- /AliParaformerAsr/Model/ConfEntity.cs: -------------------------------------------------------------------------------- 1 | // See https://github.com/manyeyes for more information 2 | // Copyright (c) 2023 by manyeyes 3 | namespace AliParaformerAsr.Model 4 | { 5 | public class ConfEntity 6 | { 7 | private int _input_size; 8 | private string _frontend = "wav_frontend"; 9 | private FrontendConfEntity _frontend_conf = new FrontendConfEntity(); 10 | private string _model = "paraformer"; 11 | private bool _use_itn = false; 12 | private ModelConfEntity _model_conf = new ModelConfEntity(); 13 | private string _preencoder = string.Empty; 14 | private PostEncoderConfEntity _preencoder_conf = new PostEncoderConfEntity(); 15 | private string _encoder = "sanm"; 16 | private EncoderConfEntity _encoder_conf = new EncoderConfEntity(); 17 | private string _postencoder = string.Empty; 18 | private PostEncoderConfEntity _postencoder_conf = new PostEncoderConfEntity(); 19 | private string _decoder = "paraformer_decoder_sanm"; 20 | private DecoderConfEntity _decoder_conf = new DecoderConfEntity(); 21 | private string _predictor = "cif_predictor_v2"; 22 | private PredictorConfEntity _predictor_conf = new PredictorConfEntity(); 23 | private string _version = string.Empty; 24 | 25 | 26 | public int input_size { get => _input_size; set => _input_size = value; } 27 | public string frontend { get => _frontend; set => _frontend = value; } 28 | public FrontendConfEntity frontend_conf { get => _frontend_conf; set => _frontend_conf = value; } 29 | public string model { get => _model; set => _model = value; } 30 | public ModelConfEntity model_conf { get => _model_conf; set => _model_conf = value; } 31 | public string preencoder { get => _preencoder; set => _preencoder = value; } 32 | public PostEncoderConfEntity preencoder_conf { get => _preencoder_conf; set => _preencoder_conf = value; } 33 | public string encoder { get => _encoder; set => _encoder = value; } 34 | public EncoderConfEntity encoder_conf { get => _encoder_conf; set => _encoder_conf = value; } 35 | public string postencoder { get => _postencoder; set => _postencoder = value; } 36 | public PostEncoderConfEntity postencoder_conf { get => _postencoder_conf; set => _postencoder_conf = value; } 37 | public string decoder { get => _decoder; set => _decoder = value; } 38 | public DecoderConfEntity decoder_conf { get => _decoder_conf; set => _decoder_conf = value; } 39 | public string predictor { get => _predictor; set => _predictor = value; } 40 | public string version { get => _version; set => _version = value; } 41 | public PredictorConfEntity predictor_conf { get => _predictor_conf; set => _predictor_conf = value; } 42 | public bool use_itn { get => _use_itn; set => _use_itn = value; } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /AliParaformerAsr/Model/OfflineYamlEntity.cs: -------------------------------------------------------------------------------- 1 | // See https://github.com/manyeyes for more information 2 | // Copyright (c) 2023 by manyeyes 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Text; 7 | using System.Threading.Tasks; 8 | 9 | namespace AliParaformerAsr.Model 10 | { 11 | internal class OfflineYamlEntity 12 | { 13 | private int _input_size; 14 | private string _frontend = "wav_frontend"; 15 | private FrontendConfEntity _frontend_conf = new FrontendConfEntity(); 16 | private string _model = "paraformer"; 17 | private ModelConfEntity _model_conf = new ModelConfEntity(); 18 | private string _preencoder = string.Empty; 19 | private PostEncoderConfEntity _preencoder_conf = new PostEncoderConfEntity(); 20 | private string _encoder = "sanm"; 21 | private EncoderConfEntity _encoder_conf = new EncoderConfEntity(); 22 | private string _postencoder = string.Empty; 23 | private PostEncoderConfEntity _postencoder_conf = new PostEncoderConfEntity(); 24 | private string _decoder = "paraformer_decoder_sanm"; 25 | private DecoderConfEntity _decoder_conf = new DecoderConfEntity(); 26 | private string _predictor = "cif_predictor_v2"; 27 | private PredictorConfEntity _predictor_conf = new PredictorConfEntity(); 28 | private string _version = string.Empty; 29 | 30 | 31 | public int input_size { get => _input_size; set => _input_size = value; } 32 | public string frontend { get => _frontend; set => _frontend = value; } 33 | public FrontendConfEntity frontend_conf { get => _frontend_conf; set => _frontend_conf = value; } 34 | public string model { get => _model; set => _model = value; } 35 | public ModelConfEntity model_conf { get => _model_conf; set => _model_conf = value; } 36 | public string preencoder { get => _preencoder; set => _preencoder = value; } 37 | public PostEncoderConfEntity preencoder_conf { get => _preencoder_conf; set => _preencoder_conf = value; } 38 | public string encoder { get => _encoder; set => _encoder = value; } 39 | public EncoderConfEntity encoder_conf { get => _encoder_conf; set => _encoder_conf = value; } 40 | public string postencoder { get => _postencoder; set => _postencoder = value; } 41 | public PostEncoderConfEntity postencoder_conf { get => _postencoder_conf; set => _postencoder_conf = value; } 42 | public string decoder { get => _decoder; set => _decoder = value; } 43 | public DecoderConfEntity decoder_conf { get => _decoder_conf; set => _decoder_conf = value; } 44 | public string predictor { get => _predictor; set => _predictor = value; } 45 | public string version { get => _version; set => _version = value; } 46 | public PredictorConfEntity predictor_conf { get => _predictor_conf; set => _predictor_conf = value; } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /AliParaformerAsr.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 17 4 | VisualStudioVersion = 17.1.32210.238 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AliParaformerAsr.Examples", "AliParaformerAsr.Examples\AliParaformerAsr.Examples.csproj", "{0CC20DAF-D6F4-481B-AE5F-09521DAC3CA2}" 7 | EndProject 8 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AliParaformerAsr", "AliParaformerAsr\AliParaformerAsr.csproj", "{763DE8F4-D05C-4317-B627-3CE1B09431A3}" 9 | EndProject 10 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{FC70D2F3-89D8-40D2-A59A-47D4960C508F}" 11 | ProjectSection(SolutionItems) = preProject 12 | LICENSE = LICENSE 13 | README.EN.md = README.EN.md 14 | README.md = README.md 15 | EndProjectSection 16 | EndProject 17 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MauiApp1", "AliParaformerAsr.Examples.MauiApp\MauiApp1.csproj", "{3190BB8F-83E1-42D8-B3CF-6C43BB419768}" 18 | EndProject 19 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AliParaformerAsr.Tests", "AliParaformerAsr.Tests\AliParaformerAsr.Tests.csproj", "{B9D49696-DEAF-48C0-AE47-3C0285BC7D78}" 20 | EndProject 21 | Global 22 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 23 | Debug|Any CPU = Debug|Any CPU 24 | Release|Any CPU = Release|Any CPU 25 | EndGlobalSection 26 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 27 | {0CC20DAF-D6F4-481B-AE5F-09521DAC3CA2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 28 | {0CC20DAF-D6F4-481B-AE5F-09521DAC3CA2}.Debug|Any CPU.Build.0 = Debug|Any CPU 29 | {0CC20DAF-D6F4-481B-AE5F-09521DAC3CA2}.Release|Any CPU.ActiveCfg = Release|Any CPU 30 | {0CC20DAF-D6F4-481B-AE5F-09521DAC3CA2}.Release|Any CPU.Build.0 = Release|Any CPU 31 | {763DE8F4-D05C-4317-B627-3CE1B09431A3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 32 | {763DE8F4-D05C-4317-B627-3CE1B09431A3}.Debug|Any CPU.Build.0 = Debug|Any CPU 33 | {763DE8F4-D05C-4317-B627-3CE1B09431A3}.Release|Any CPU.ActiveCfg = Release|Any CPU 34 | {763DE8F4-D05C-4317-B627-3CE1B09431A3}.Release|Any CPU.Build.0 = Release|Any CPU 35 | {3190BB8F-83E1-42D8-B3CF-6C43BB419768}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 36 | {3190BB8F-83E1-42D8-B3CF-6C43BB419768}.Debug|Any CPU.Build.0 = Debug|Any CPU 37 | {3190BB8F-83E1-42D8-B3CF-6C43BB419768}.Debug|Any CPU.Deploy.0 = Debug|Any CPU 38 | {3190BB8F-83E1-42D8-B3CF-6C43BB419768}.Release|Any CPU.ActiveCfg = Release|Any CPU 39 | {3190BB8F-83E1-42D8-B3CF-6C43BB419768}.Release|Any CPU.Build.0 = Release|Any CPU 40 | {3190BB8F-83E1-42D8-B3CF-6C43BB419768}.Release|Any CPU.Deploy.0 = Release|Any CPU 41 | {B9D49696-DEAF-48C0-AE47-3C0285BC7D78}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 42 | {B9D49696-DEAF-48C0-AE47-3C0285BC7D78}.Debug|Any CPU.Build.0 = Debug|Any CPU 43 | {B9D49696-DEAF-48C0-AE47-3C0285BC7D78}.Release|Any CPU.ActiveCfg = Release|Any CPU 44 | {B9D49696-DEAF-48C0-AE47-3C0285BC7D78}.Release|Any CPU.Build.0 = Release|Any CPU 45 | EndGlobalSection 46 | GlobalSection(SolutionProperties) = preSolution 47 | HideSolutionNode = FALSE 48 | EndGlobalSection 49 | GlobalSection(ExtensibilityGlobals) = postSolution 50 | SolutionGuid = {FADC677C-FC04-47A3-B4DE-704D30A42AF8} 51 | EndGlobalSection 52 | EndGlobal 53 | -------------------------------------------------------------------------------- /AliParaformerAsr/Utils/PadHelper.cs: -------------------------------------------------------------------------------- 1 | using AliParaformerAsr.Model; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace AliParaformerAsr.Utils 9 | { 10 | internal static class PadHelper 11 | { 12 | public static float[] PadSequence(List modelInputs) 13 | { 14 | List floats = modelInputs.Where(x => x != null).Select(x => x.Speech).ToList(); 15 | return PadSequence(floats); 16 | } 17 | public static float[] PadSequence(List modelInputs) 18 | { 19 | List floats = modelInputs.Where(x => x != null).Select(x => x.Speech).ToList(); 20 | return PadSequence(floats, tailLen:0); 21 | } 22 | 23 | private static float[] PadSequence(List floats, int tailLen = 0) 24 | { 25 | int max_speech_length = floats.Where(x => x != null).Max(x => x.Length) + 560 * tailLen; 26 | int speech_length = max_speech_length * floats.Count; 27 | float[] speech = new float[speech_length]; 28 | float[,] xxx = new float[floats.Count, max_speech_length]; 29 | for (int i = 0; i < floats.Count; i++) 30 | { 31 | if (floats[i] == null || max_speech_length == floats[i].Length) 32 | { 33 | for (int j = 0; j < xxx.GetLength(1); j++) 34 | { 35 | #pragma warning disable CS8602 // 解引用可能出现空引用。 36 | xxx[i, j] = floats[i][j]; 37 | #pragma warning restore CS8602 // 解引用可能出现空引用。 38 | } 39 | continue; 40 | } 41 | float[] nullspeech = new float[max_speech_length - floats[i].Length]; 42 | float[]? curr_speech = floats[i]; 43 | float[] padspeech = new float[max_speech_length]; 44 | Array.Copy(curr_speech, 0, padspeech, 0, curr_speech.Length); 45 | //Array.Copy(nullspeech, 0, padspeech, curr_speech.Length, nullspeech.Length); 46 | for (int j = 0; j < padspeech.Length; j++) 47 | { 48 | #pragma warning disable CS8602 // 解引用可能出现空引用。 49 | xxx[i, j] = padspeech[j]; 50 | #pragma warning restore CS8602 // 解引用可能出现空引用。 51 | } 52 | } 53 | //Array.Copy(xxx, 0, speech, 0, speech.Length);//one len is 3120 54 | int s = 0; 55 | for (int i = 0; i < xxx.GetLength(0); i++) 56 | { 57 | for (int j = 0; j < xxx.GetLength(1); j++) 58 | { 59 | speech[s] = xxx[i, j]; 60 | s++; 61 | } 62 | } 63 | speech = speech.Select(x => x == 0 ? -23.025850929940457F * 32768 : x).ToArray(); 64 | return speech; 65 | } 66 | 67 | public static float[] PadSequence_unittest(List modelInputs) 68 | { 69 | int max_speech_length = modelInputs.Max(x => x.SpeechLength); 70 | int speech_length = max_speech_length * modelInputs.Count; 71 | float[] speech = new float[speech_length]; 72 | for (int i = 0; i < modelInputs.Count; i++) 73 | { 74 | float[]? curr_speech = modelInputs[i].Speech; 75 | Array.Copy(curr_speech, 0, speech, i * curr_speech.Length, curr_speech.Length); 76 | } 77 | speech = speech.Select(x => x == 0 ? -23.025850929940457F * 32768 : x).ToArray(); 78 | return speech; 79 | } 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /AliParaformerAsr/EmbedSVModel.cs: -------------------------------------------------------------------------------- 1 | // See https://github.com/manyeyes for more information 2 | // Copyright (c) 2024 by manyeyes 3 | using Microsoft.ML.OnnxRuntime; 4 | using Microsoft.ML.OnnxRuntime.Tensors; 5 | //using System.Reflection; 6 | 7 | namespace AliParaformerAsr 8 | { 9 | public class EmbedSVModel 10 | { 11 | private InferenceSession _modelSession; 12 | 13 | public EmbedSVModel(int threadsNum = 2) 14 | { 15 | _modelSession = initModel(threadsNum); 16 | } 17 | public InferenceSession ModelSession { get => _modelSession; set => _modelSession = value; } 18 | 19 | public InferenceSession initModel(int threadsNum = 2) 20 | { 21 | byte[] model = ReadEmbeddedResourceAsBytes("AliParaformerAsr.data.embed.onnx"); 22 | Microsoft.ML.OnnxRuntime.SessionOptions options = new Microsoft.ML.OnnxRuntime.SessionOptions(); 23 | options.LogSeverityLevel = OrtLoggingLevel.ORT_LOGGING_LEVEL_FATAL; 24 | //options.AppendExecutionProvider_DML(0); 25 | options.AppendExecutionProvider_CPU(0); 26 | //options.AppendExecutionProvider_CUDA(0); 27 | options.InterOpNumThreads = threadsNum; 28 | InferenceSession onnxSession = new InferenceSession(model, options); 29 | return onnxSession; 30 | } 31 | private static byte[] ReadEmbeddedResourceAsBytes(string resourceName) 32 | { 33 | //var assembly = Assembly.GetExecutingAssembly(); 34 | var assembly = typeof(EmbedSVModel).Assembly; 35 | 36 | var stream = assembly.GetManifestResourceStream(resourceName) ?? 37 | throw new FileNotFoundException($"Embedded resource '{resourceName}' not found."); 38 | byte[] bytes = new byte[stream.Length]; 39 | stream.Read(bytes, 0, bytes.Length); 40 | stream.Seek(0, SeekOrigin.Begin); 41 | stream.Close(); 42 | stream.Dispose(); 43 | return bytes; 44 | } 45 | public float[] Forward(Int64[] x,int speechSize=0) 46 | { 47 | float[] y=new float[0]; 48 | var inputMeta = _modelSession.InputMetadata; 49 | var container = new List(); 50 | foreach (var name in inputMeta.Keys) 51 | { 52 | if (name == "x") 53 | { 54 | int[] dim = new int[] { 1,x.Length }; 55 | var tensor = new DenseTensor(x, dim, false); 56 | container.Add(NamedOnnxValue.CreateFromTensor(name, tensor)); 57 | } 58 | } 59 | //IReadOnlyCollection outputNames = new List(); 60 | //outputNames.Append("y"); 61 | IDisposableReadOnlyCollection results = null; 62 | try 63 | { 64 | results = _modelSession.Run(container); 65 | if (results != null) 66 | { 67 | var resultsArray = results.ToArray(); 68 | Tensor logits_tensor = resultsArray[0].AsTensor(); 69 | y = logits_tensor.ToArray(); 70 | } 71 | } 72 | catch (Exception ex) 73 | { 74 | throw new Exception("Embed SV Forward failed", ex.InnerException); 75 | } 76 | return y; 77 | } 78 | protected virtual void Dispose(bool disposing) 79 | { 80 | if (disposing) 81 | { 82 | if (_modelSession != null) 83 | { 84 | _modelSession.Dispose(); 85 | } 86 | } 87 | } 88 | 89 | internal void Dispose() 90 | { 91 | Dispose(disposing: true); 92 | GC.SuppressFinalize(this); 93 | } 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /AliParaformerAsr/AliParaformerAsr.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net461;net472;net48;netstandard2.0;netstandard2.1;netcoreapp3.1;net6.0;net8.0;net8.0-android;net8.0-ios;net8.0-maccatalyst 5 | $(TargetFrameworks);net8.0-windows10.0.19041.0 6 | 7 | 10.0.19041.0 8 | 21.0 9 | 14.2 10 | 15.0 11 | 12 | $(DefineConstants);MODERN_DOTNET 13 | 10 14 | enable 15 | enable 16 | 17 | ManySpeech.AliParaformerAsr 18 | 1.1.8 19 | manyeyes contributors 20 | manyeyes contributors 21 | Copyright © manyeyes contributors 22 | c# library for decoding paraformer, sensevoice Models,used in speech recognition (ASR) 23 | c# library for decoding paraformer, sensevoice Models,used in speech recognition (ASR).Paraformer is an efficient non autoregressive end-to-end speech recognition framework proposed by the speech team at Damo Institute. This project is a Paraformer Chinese universal speech recognition model, which uses tens of thousands of hours of industrial grade annotated audio for model training to ensure the universal recognition effect of the model. The model can be applied to scenarios such as voice input methods, voice navigation, and intelligent meeting minutes. Accuracy: High. 24 | speech recognition asr paraformer sensevoice ai local privacy 25 | https://github.com/manyeyes/AliParaformerAsr 26 | https://github.com/manyeyes/AliParaformerAsr 27 | true 28 | snupkg 29 | enable 30 | latest 31 | App_Readme/README.EN.md 32 | App_Readme/LICENSE 33 | true 34 | 35 | App_Readme/README.md 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | -------------------------------------------------------------------------------- /AliParaformerAsr/OfflineStream.cs: -------------------------------------------------------------------------------- 1 | // See https://github.com/manyeyes for more information 2 | // Copyright (c) 2023 by manyeyes 3 | using AliParaformerAsr.Model; 4 | 5 | namespace AliParaformerAsr 6 | { 7 | public class OfflineStream : IDisposable 8 | { 9 | private bool _disposed; 10 | 11 | private WavFrontend _wavFrontend; 12 | private OfflineInputEntity _offlineInputEntity; 13 | private int _blank_id = 0; 14 | private int _unk_id = 2; 15 | private Int64[] _hyp; 16 | private List? _hotwords = new List(); 17 | List _tokens = new List(); 18 | List _timestamps = new List(); 19 | private static object obj = new object(); 20 | public OfflineStream(string mvnFilePath, ConfEntity confEntity) 21 | { 22 | _offlineInputEntity = new OfflineInputEntity(); 23 | 24 | _wavFrontend = new WavFrontend(mvnFilePath, confEntity.frontend_conf); 25 | _hyp = new Int64[] { _blank_id, _blank_id }; 26 | _tokens = new List { _blank_id, _blank_id }; 27 | _timestamps = new List { }; 28 | } 29 | 30 | public OfflineInputEntity OfflineInputEntity { get => _offlineInputEntity; set => _offlineInputEntity = value; } 31 | public Int64[] Hyp { get => _hyp; set => _hyp = value; } 32 | public List Tokens { get => _tokens; set => _tokens = value; } 33 | public List Timestamps { get => _timestamps; set => _timestamps = value; } 34 | public List? Hotwords { get => _hotwords; set => _hotwords = value; } 35 | 36 | public void AddSamples(float[] samples) 37 | { 38 | lock (obj) 39 | { 40 | float[] fbanks = _wavFrontend.GetFbank(samples); 41 | float[] features = _wavFrontend.LfrCmvn(fbanks); 42 | int oLen = 0; 43 | if (OfflineInputEntity.SpeechLength > 0) 44 | { 45 | oLen = OfflineInputEntity.SpeechLength; 46 | } 47 | float[]? featuresTemp = new float[oLen + features.Length]; 48 | if (OfflineInputEntity.SpeechLength > 0) 49 | { 50 | Array.Copy(_offlineInputEntity.Speech, 0, featuresTemp, 0, _offlineInputEntity.SpeechLength); 51 | } 52 | Array.Copy(features, 0, featuresTemp, OfflineInputEntity.SpeechLength, features.Length); 53 | OfflineInputEntity.Speech = featuresTemp; 54 | OfflineInputEntity.SpeechLength = featuresTemp.Length; 55 | OfflineInputEntity.Hotwords = Hotwords; 56 | } 57 | } 58 | public OfflineInputEntity GetDecodeChunk() 59 | { 60 | lock (obj) 61 | { 62 | if (OfflineInputEntity.Speech != null && OfflineInputEntity.SpeechLength > 0) 63 | { 64 | OfflineInputEntity.Hotwords = Hotwords; 65 | } 66 | return OfflineInputEntity; 67 | } 68 | } 69 | public void RemoveChunk() 70 | { 71 | lock (obj) 72 | { 73 | if (_tokens.Count > 2) 74 | { 75 | OfflineInputEntity.Speech = null; 76 | OfflineInputEntity.SpeechLength = 0; 77 | } 78 | } 79 | } 80 | protected virtual void Dispose(bool disposing) 81 | { 82 | if (!_disposed) 83 | { 84 | if (disposing) 85 | { 86 | if (_wavFrontend != null) 87 | { 88 | _wavFrontend.Dispose(); 89 | } 90 | if (_offlineInputEntity != null) 91 | { 92 | _offlineInputEntity = null; 93 | } 94 | if (_hyp != null) 95 | { 96 | _hyp = null; 97 | } 98 | if (_tokens != null) 99 | { 100 | _tokens = null; 101 | } 102 | if (_timestamps != null) 103 | { 104 | _timestamps = null; 105 | } 106 | } 107 | _disposed = true; 108 | } 109 | } 110 | 111 | public void Dispose() 112 | { 113 | Dispose(disposing: true); 114 | GC.SuppressFinalize(this); 115 | } 116 | ~OfflineStream() 117 | { 118 | Dispose(_disposed); 119 | } 120 | } 121 | } 122 | -------------------------------------------------------------------------------- /AliParaformerAsr/OfflineModel.cs: -------------------------------------------------------------------------------- 1 | // See https://github.com/manyeyes for more information 2 | // Copyright (c) 2023 by manyeyes 3 | using Microsoft.ML.OnnxRuntime; 4 | //using System.Reflection; 5 | 6 | namespace AliParaformerAsr 7 | { 8 | public class OfflineModel 9 | { 10 | private InferenceSession _modelSession; 11 | private string _modelebFilePath; 12 | private List? _hotwords = null; 13 | private int _blank_id = 0; 14 | private int _sos_eos_id = 1; 15 | private int _unk_id = 2; 16 | private int _featureDim = 80; 17 | private int _sampleRate = 16000; 18 | private bool _use_itn = false; 19 | 20 | public OfflineModel(string modelFilePath, string modelebFilePath = "", int threadsNum = 2) 21 | { 22 | _modelSession = initModel(modelFilePath, threadsNum); 23 | _modelebFilePath = modelebFilePath; 24 | } 25 | public int Blank_id { get => _blank_id; set => _blank_id = value; } 26 | public int Sos_eos_id { get => _sos_eos_id; set => _sos_eos_id = value; } 27 | public int Unk_id { get => _unk_id; set => _unk_id = value; } 28 | public int FeatureDim { get => _featureDim; set => _featureDim = value; } 29 | public InferenceSession ModelSession { get => _modelSession; set => _modelSession = value; } 30 | public int SampleRate { get => _sampleRate; set => _sampleRate = value; } 31 | public bool Use_itn { get => _use_itn; set => _use_itn = value; } 32 | public string ModelebFilePath { get => _modelebFilePath; set => _modelebFilePath = value; } 33 | public List? Hotwords { get => _hotwords; set => _hotwords = value; } 34 | 35 | public InferenceSession initModel(string modelFilePath, int threadsNum = 2) 36 | { 37 | if (string.IsNullOrEmpty(modelFilePath) || !File.Exists(modelFilePath)) 38 | { 39 | return null; 40 | } 41 | Microsoft.ML.OnnxRuntime.SessionOptions options = new Microsoft.ML.OnnxRuntime.SessionOptions(); 42 | //options.LogSeverityLevel = OrtLoggingLevel.ORT_LOGGING_LEVEL_INFO; 43 | options.LogSeverityLevel = OrtLoggingLevel.ORT_LOGGING_LEVEL_FATAL; 44 | options.GraphOptimizationLevel = GraphOptimizationLevel.ORT_ENABLE_ALL; // 启用所有图优化 45 | //options.AppendExecutionProvider_DML(0); 46 | options.AppendExecutionProvider_CPU(0); 47 | //options.AppendExecutionProvider_CUDA(0); 48 | //options.AppendExecutionProvider_MKLDNN(); 49 | //options.AppendExecutionProvider_ROCm(0); 50 | if (threadsNum > 0) 51 | options.InterOpNumThreads = threadsNum; 52 | else 53 | options.InterOpNumThreads = System.Environment.ProcessorCount; 54 | // 启用CPU内存计划 55 | options.EnableMemoryPattern = true; 56 | // 设置其他优化选项 57 | options.GraphOptimizationLevel = GraphOptimizationLevel.ORT_ENABLE_ALL; 58 | 59 | InferenceSession onnxSession = null; 60 | if (!string.IsNullOrEmpty(modelFilePath) && modelFilePath.IndexOf("/") < 0 && modelFilePath.IndexOf("\\") < 0) 61 | { 62 | byte[] model = ReadEmbeddedResourceAsBytes(modelFilePath); 63 | onnxSession = new InferenceSession(model, options); 64 | } 65 | else 66 | { 67 | onnxSession = new InferenceSession(modelFilePath, options); 68 | } 69 | return onnxSession; 70 | } 71 | 72 | private static byte[] ReadEmbeddedResourceAsBytes(string resourceName) 73 | { 74 | //var assembly = Assembly.GetExecutingAssembly(); 75 | var assembly = typeof(OfflineModel).Assembly; 76 | var stream = assembly.GetManifestResourceStream(resourceName) ?? 77 | throw new FileNotFoundException($"Embedded resource '{resourceName}' not found."); 78 | byte[] bytes = new byte[stream.Length]; 79 | stream.Read(bytes, 0, bytes.Length); 80 | // 设置当前流的位置为流的开始 81 | stream.Seek(0, SeekOrigin.Begin); 82 | stream.Close(); 83 | stream.Dispose(); 84 | 85 | return bytes; 86 | } 87 | 88 | protected virtual void Dispose(bool disposing) 89 | { 90 | if (disposing) 91 | { 92 | if (_modelSession != null) 93 | { 94 | _modelSession.Dispose(); 95 | } 96 | } 97 | } 98 | 99 | internal void Dispose() 100 | { 101 | Dispose(disposing: true); 102 | GC.SuppressFinalize(this); 103 | } 104 | } 105 | } 106 | -------------------------------------------------------------------------------- /AliParaformerAsr/OfflineProjOfParaformer.cs: -------------------------------------------------------------------------------- 1 | // See https://github.com/manyeyes for more information 2 | // Copyright (c) 2023 by manyeyes 3 | using AliParaformerAsr.Model; 4 | using AliParaformerAsr.Utils; 5 | using Microsoft.ML.OnnxRuntime; 6 | using Microsoft.ML.OnnxRuntime.Tensors; 7 | 8 | namespace AliParaformerAsr 9 | { 10 | internal class OfflineProjOfParaformer : IOfflineProj, IDisposable 11 | { 12 | // To detect redundant calls 13 | private bool _disposed; 14 | 15 | private InferenceSession _modelSession; 16 | private int _blank_id = 0; 17 | private int _sos_eos_id = 1; 18 | private int _unk_id = 2; 19 | 20 | private int _featureDim = 80; 21 | private int _sampleRate = 16000; 22 | 23 | public OfflineProjOfParaformer(OfflineModel offlineModel) 24 | { 25 | _modelSession = offlineModel.ModelSession; 26 | _blank_id = offlineModel.Blank_id; 27 | _sos_eos_id = offlineModel.Sos_eos_id; 28 | _unk_id = offlineModel.Unk_id; 29 | _featureDim = offlineModel.FeatureDim; 30 | _sampleRate = offlineModel.SampleRate; 31 | } 32 | public InferenceSession ModelSession { get => _modelSession; set => _modelSession = value; } 33 | public int Blank_id { get => _blank_id; set => _blank_id = value; } 34 | public int Sos_eos_id { get => _sos_eos_id; set => _sos_eos_id = value; } 35 | public int Unk_id { get => _unk_id; set => _unk_id = value; } 36 | public int FeatureDim { get => _featureDim; set => _featureDim = value; } 37 | public int SampleRate { get => _sampleRate; set => _sampleRate = value; } 38 | 39 | public ModelOutputEntity ModelProj(List modelInputs) 40 | { 41 | int batchSize = modelInputs.Count; 42 | float[] padSequence = PadHelper.PadSequence(modelInputs); 43 | var inputMeta = _modelSession.InputMetadata; 44 | var container = new List(); 45 | foreach (var name in inputMeta.Keys) 46 | { 47 | if (name == "speech") 48 | { 49 | int[] dim = new int[] { batchSize, padSequence.Length / 560 / batchSize, 560 }; 50 | var tensor = new DenseTensor(padSequence, dim, false); 51 | container.Add(NamedOnnxValue.CreateFromTensor(name, tensor)); 52 | } 53 | if (name == "speech_lengths") 54 | { 55 | int[] dim = new int[] { batchSize }; 56 | int[] speech_lengths = new int[batchSize]; 57 | for (int i = 0; i < batchSize; i++) 58 | { 59 | speech_lengths[i] = padSequence.Length / 560 / batchSize; 60 | } 61 | var tensor = new DenseTensor(speech_lengths, dim, false); 62 | container.Add(NamedOnnxValue.CreateFromTensor(name, tensor)); 63 | } 64 | } 65 | ModelOutputEntity modelOutputEntity = new ModelOutputEntity(); 66 | try 67 | { 68 | IDisposableReadOnlyCollection results = _modelSession.Run(container); 69 | 70 | if (results != null) 71 | { 72 | var resultsArray = results.ToArray(); 73 | modelOutputEntity.model_out = resultsArray[0].AsTensor(); 74 | modelOutputEntity.model_out_lens = resultsArray[1].AsEnumerable().ToArray(); 75 | if (resultsArray.Length >= 4) 76 | { 77 | Tensor cif_peak_tensor = resultsArray[3].AsTensor(); 78 | modelOutputEntity.cif_peak_tensor = cif_peak_tensor; 79 | } 80 | } 81 | } 82 | catch (Exception ex) 83 | { 84 | throw new Exception("ModelProj failed", ex); 85 | } 86 | return modelOutputEntity; 87 | } 88 | protected virtual void Dispose(bool disposing) 89 | { 90 | if (!_disposed) 91 | { 92 | if (disposing) 93 | { 94 | if (_modelSession != null) 95 | { 96 | _modelSession.Dispose(); 97 | } 98 | } 99 | _disposed = true; 100 | } 101 | } 102 | 103 | public void Dispose() 104 | { 105 | Dispose(disposing: true); 106 | GC.SuppressFinalize(this); 107 | } 108 | ~OfflineProjOfParaformer() 109 | { 110 | Dispose(_disposed); 111 | } 112 | } 113 | } 114 | -------------------------------------------------------------------------------- /AliParaformerAsr.Examples.MauiApp/RecognitionForFiles.xaml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 |