sapi文本转成声音

使用微软的SAPI实现文本转成声音,功能基本可以实现,效果达不到非常满意。其中有几个问题还没有完全解决,望哪位高手帮忙指点,谢谢啦。

1、标点符号和英文单词之间没有空格分隔,标点符号问号?读成问题question。

2、怎么设置停顿 ?解决方法:使用标点符号?停顿,例如:A   ?    How are you?

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SpeechLib;
using System.Collections;

namespace SpeechDemo
{
    public class SpeechHelper
    {

        #region Field

        private SpeechLib.SpVoiceClass voice = null;
        private static SpeechHelper instance;

        #endregion

        #region Contructor

        private SpeechHelper()
        {
            if (voice == null)
            {
                voice = new SpeechLib.SpVoiceClass();
                voice.EndStream += new _ISpeechVoiceEvents_EndStreamEventHandler(voice_EndStream);
            }
        }

        #endregion

        #region Event

        public delegate void EndStreamEventHandler();
        public event EndStreamEventHandler EndStream;

        #endregion

        #region Method

        void voice_EndStream(int StreamNumber, object StreamPosition)
        {
            if (EndStream != null)
            {
                EndStream();
            }
        }

        public static SpeechHelper GetInstance()
        {
            if (instance == null)
            {
                instance = new SpeechHelper();
            }
            return instance;
        }


        public void SetRate(int rate)
        {
            voice.Rate = rate;
        }

        public void SetVolume(int volume)
        {
            voice.Volume = volume;
        }

        public void SetRole(int role)
        {
            voice.Voice = voice.GetVoices(string.Empty, string.Empty).Item(role);
        }

        public void Speak(string text)
        {
            if (string.IsNullOrEmpty(text))
            {
                return;
            }
            voice.Speak(text, SpeechVoiceSpeakFlags.SVSFlagsAsync);
        }

        public void Resume()
        {
            voice.Resume();
        }

        public void Pause()
        {
            voice.Pause();
        }

        public void Stop()
        {
            voice.Speak(string.Empty, SpeechLib.SpeechVoiceSpeakFlags.SVSFPurgeBeforeSpeak);
        }

        public ArrayList GetAllRole()
        {
            ArrayList roleArr = new ArrayList();
            for (int i = 0; i < voice.GetVoices(string.Empty, string.Empty).Count; i++)
            {
                roleArr.Add(voice.GetVoices(string.Empty, string.Empty).Item(i).GetDescription(0));
            }
            return roleArr;
        }

        #endregion

    }
}


 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值