Wrap punctuation APIs to C#. (#945)

This commit is contained in:
Fangjun Kuang
2024-05-30 16:19:56 +08:00
committed by GitHub
parent 082f230dfb
commit a99c7cb35c
31 changed files with 263 additions and 55 deletions

View File

@@ -0,0 +1,45 @@
// 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("---------");
}
}
}

View File

@@ -0,0 +1,15 @@
<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>

View File

@@ -0,0 +1,11 @@
#!/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