TextToSpeech issues

https://github.com/dotnet/maui/issues?q=TextToSpeech

https://learn.microsoft.com/zh-tw/dotnet/maui/platform-integration/device-media/text-to-speech?view=net-maui-7.0&tabs=windows

播放器

https://blog.csdn.net/weixin_43811612/article/details/129072398

https://github.com/CommunityToolkit/Maui/discussions/929

https://github.com/CommunityToolkit/Maui

Essentials.TextToSpeech

https://github.com/dotnet/maui/pull/4747

System.Speech

https://dot.net/

https://www.nuget.org/packages/System.Speech/8.0.0

带动画示例

https://github.com/pierre01/TimerFaceMockup

语音包

https://www.coder.work/article/2932177

女声改男声

https://blog.csdn.net/u012161365/article/details/88719612

官网API

https://learn.microsoft.com/zh-cn/dotnet/maui/platform-integration/device-media/text-to-speech

语音工具

https://learn.microsoft.com/en-us/previous-versions/office/developer/speech-technologies/hh378335(v=office.14)

Maui TextToSpeech库提供了一些方法来设置语速和声音,具体取决于你使用的平台和库版本。

在Maui TextToSpeech中,你可以使用以下代码设置语速:


Speech.Speak("Hello World", new SpeechOptions()
{
    Volume = 1.0f,
    Pitch = 1.0f,
    Rate = 1.0f // 这里是语速,1.0 表示正常速度
});
Speech.Speak("Hello World", new SpeechOptions()
{
    Volume = 1.0f,
    Pitch = 1.0f,
    Rate = 1.0f // 这里是语速,1.0 表示正常速度
});

对于声音设置,如果你使用的是Android平台,你可以在app的MainActivity文件中添加以下代码:


protected override void OnCreate(Bundle savedInstanceState)
{
    // ...

    // 在这里设置为英式发音
    var config = new SpeechConfig(Android.App.Application.Context, "com.google.android.tts");
    config.SetParameter(SpeechConfig.KeyLanguage, "en-US");
    config.SetParameter(SpeechConfig.KeyVariant, "British"); // 英式发音

    DependencyService.RegisterSingleton(config);

    // ...
}
protected override void OnCreate(Bundle savedInstanceState)
{
    // ...

    // 在这里设置为英式发音
    var config = new SpeechConfig(Android.App.Application.Context, "com.google.android.tts");
    config.SetParameter(SpeechConfig.KeyLanguage, "en-US");
    config.SetParameter(SpeechConfig.KeyVariant, "British"); // 英式发音

    DependencyService.RegisterSingleton(config);

    // ...
}


如果你使用的是iOS平台,你可以在AppDelegate.cs文件中添加以下代码:

public override bool FinishedLaunching(UIApplication app, NSDictionary options)
{
    // ...

    // 在这里设置为英式发音
    var config = new SpeechConfig("com.apple.ttsbundle.siri_female_en-GB_compact"); // 英式发音
    DependencyService.RegisterSingleton(config);

    // ...
}
public override bool FinishedLaunching(UIApplication app, NSDictionary options)
{
    // ...

    // 在这里设置为英式发音
    var config = new SpeechConfig("com.apple.ttsbundle.siri_female_en-GB_compact"); // 英式发音
    DependencyService.RegisterSingleton(config);

    // ...
}
​
using Microsoft.Maui.Essentials;

// 设置所需的语言

var locales = await TextToSpeech.GetLocalesAsync();
var locale = locales.FirstOrDefault(l => l.Language.Contains("en"));

// 选择所需的声音

var voices = await TextToSpeech.GetVoicesAsync();
var voice = voices.FirstOrDefault(v => v.Name.Equals("Microsoft Server Speech Text to Speech Voice (en-US, BenjaminRUS)"));

// 初始化TextToSpeech

var settings = new SpeechOptions
{
    Locale = locale,
    Voice = voice
};
var textToSpeech = TextToSpeech.SpeakAsync("Hello world!", settings);
文档更新时间: 2023-11-19 08:46   作者:admin