C#基础:使用System.Speech.Synthesis离线播放/朗读文字内容

一、Nuget包

注意版本号,例如你的是NET6,那就要安装NET6版本的Nuget

二、源代码

cs 复制代码
using System.Speech.Synthesis;

class Program
{
    static void Main()
    {
        string txt = "你好世界!这里是C#文字转语音";
        PlayTxt(txt);
    }

    private static void PlayTxt(string txt)
    {

        using (var synth = new SpeechSynthesizer())
        {
            // 设置中文语音(Windows 内置)
            synth.SelectVoiceByHints(VoiceGender.Female, VoiceAge.Adult, 0, new System.Globalization.CultureInfo("zh-CN"));
            synth.Volume = 100;    // 0-100
            synth.Rate = 0;        // -10 到 10
            synth.Speak(txt);      // 同步朗读,直到结束
        }
    }
}
相关推荐
meiying88381 小时前
快递单号批量查询Python脚本:从手动到自动化的完整实现
开发语言·python·自动化
@大迁世界2 小时前
告别 Go,拥抱 Rust
开发语言·golang·rust
SEO_juper2 小时前
Node.js 重定向链检测工具:301 跳了几跳、有没有成环,一次看清
xml·开发语言·python·node.js·json·bash
学逆向的2 小时前
C 指针常量与常量指针
c语言·开发语言·网络安全
低调滴开发2 小时前
3 行代码写崩一个函数?切片才是 Rust 字符串处理的正确姿势
开发语言·后端·rust
CodeYp20193 小时前
第15讲:二叉搜索树
开发语言·c++·二叉搜索树
猫猫.1533 小时前
HashTable、HashMap、ConcurrentHashMap 核心区别总结
java·开发语言·java-ee
乌暮4 小时前
综合案例:宠物电商系统
java·开发语言·spring·mvc·restful·1024程序员节
大文说跨境4 小时前
亚马逊多店铺的图片素材怎么批量去重:EXIF 与哈希的处理流程
开发语言·php
大风起兮云飞扬丶5 小时前
Java——枚举
java·开发语言