using System;
using System.Collections.Generic;
using System.Text;namespace SpeachTemp
{
class Speach_temp
{
private static Speach_temp _Instance = null;
private SpeechLib.SpVoiceClass voice = null;
private Speach_temp()
{
BuildSpeach();
}
public static Speach_temp instance()
{ if (_Instance == null) _Instance = new Speach_temp(); return _Instance; }
private void SetChinaVoice()
{ voice.Voice = voice.GetVoices(string.Empty, string.Empty).Item(0); }
private void SetEnglishVoice()
{ voice.Voice = voice.GetVoices(string.Empty, string.Empty).Item(1); }
public void SpeakChina(string strSpeak)
{ SetChinaVoice(); Speak(strSpeak); }
private void SpeakEnglishi(string strSpeak)
{ SetEnglishVoice(); Speak(strSpeak); }
public void AnalyseSpeak(string strSpeak)
{ int iCbeg = 0; int iEbeg = 0; bool IsChina = true; for (int i = 0; i < strSpeak.Length; i++)
{ char chr = strSpeak[i]; if (IsChina)
{ if (chr <= 122 && chr >= 65)
{ int iLen = i - iCbeg; string strValue = strSpeak.Substring(iCbeg, iLen); SpeakChina(strValue); iEbeg = i; IsChina = false; } } else
{ if (chr > 122 || chr < 65)
{ int iLen = i - iEbeg; string strValue = strSpeak.Substring(iEbeg, iLen); this.SpeakEnglishi(strValue); iCbeg = i; IsChina = true; } } }//end for if (IsChina)
{ int iLen = strSpeak.Length - iCbeg; string strValue = strSpeak.Substring(iCbeg, iLen); SpeakChina(strValue); } else
{ int iLen = strSpeak.Length - iEbeg; string strValue = strSpeak.Substring(iEbeg, iLen); SpeakEnglishi(strValue); } }
public void BuildSpeach()
{ if (voice == null) voice = new SpeechLib.SpVoiceClass(); }
public int Volume
{ get
{ return voice.Volume; } set
{ voice.SetVolume((ushort)(value)); } }
public int Rate
{ get
{ return voice.Rate; } set
{ voice.SetRate(value); } }
public void Speak(string strSpeack)
{ try
{ voice.Speak(strSpeack, SpeechLib.SpeechVoiceSpeakFlags.SVSFlagsAsync); } catch (Exception err)
{ throw (new Exception("发生一个错误:" + err.Message)); } }
public void Stop()
{ voice.Speak(string.Empty, SpeechLib.SpeechVoiceSpeakFlags.SVSFPurgeBeforeSpeak); } public void Pause()
{ voice.Pause(); } public void Continue()
{ voice.Resume(); }
}
}using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;namespace SpeachTemp
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} private void button1_Click(object sender, EventArgs e)
{
Speach_temp speach = new Speach_temp();//提示这里出错。
speach.SpeakChina(textBox1.Text.Trim());
}
}
}
为什么会提示我不可访问或受限制呢???谁明白,请告知!!!
using System.Collections.Generic;
using System.Text;namespace SpeachTemp
{
class Speach_temp
{
private static Speach_temp _Instance = null;
private SpeechLib.SpVoiceClass voice = null;
private Speach_temp()
{
BuildSpeach();
}
public static Speach_temp instance()
{ if (_Instance == null) _Instance = new Speach_temp(); return _Instance; }
private void SetChinaVoice()
{ voice.Voice = voice.GetVoices(string.Empty, string.Empty).Item(0); }
private void SetEnglishVoice()
{ voice.Voice = voice.GetVoices(string.Empty, string.Empty).Item(1); }
public void SpeakChina(string strSpeak)
{ SetChinaVoice(); Speak(strSpeak); }
private void SpeakEnglishi(string strSpeak)
{ SetEnglishVoice(); Speak(strSpeak); }
public void AnalyseSpeak(string strSpeak)
{ int iCbeg = 0; int iEbeg = 0; bool IsChina = true; for (int i = 0; i < strSpeak.Length; i++)
{ char chr = strSpeak[i]; if (IsChina)
{ if (chr <= 122 && chr >= 65)
{ int iLen = i - iCbeg; string strValue = strSpeak.Substring(iCbeg, iLen); SpeakChina(strValue); iEbeg = i; IsChina = false; } } else
{ if (chr > 122 || chr < 65)
{ int iLen = i - iEbeg; string strValue = strSpeak.Substring(iEbeg, iLen); this.SpeakEnglishi(strValue); iCbeg = i; IsChina = true; } } }//end for if (IsChina)
{ int iLen = strSpeak.Length - iCbeg; string strValue = strSpeak.Substring(iCbeg, iLen); SpeakChina(strValue); } else
{ int iLen = strSpeak.Length - iEbeg; string strValue = strSpeak.Substring(iEbeg, iLen); SpeakEnglishi(strValue); } }
public void BuildSpeach()
{ if (voice == null) voice = new SpeechLib.SpVoiceClass(); }
public int Volume
{ get
{ return voice.Volume; } set
{ voice.SetVolume((ushort)(value)); } }
public int Rate
{ get
{ return voice.Rate; } set
{ voice.SetRate(value); } }
public void Speak(string strSpeack)
{ try
{ voice.Speak(strSpeack, SpeechLib.SpeechVoiceSpeakFlags.SVSFlagsAsync); } catch (Exception err)
{ throw (new Exception("发生一个错误:" + err.Message)); } }
public void Stop()
{ voice.Speak(string.Empty, SpeechLib.SpeechVoiceSpeakFlags.SVSFPurgeBeforeSpeak); } public void Pause()
{ voice.Pause(); } public void Continue()
{ voice.Resume(); }
}
}using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;namespace SpeachTemp
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} private void button1_Click(object sender, EventArgs e)
{
Speach_temp speach = new Speach_temp();//提示这里出错。
speach.SpeakChina(textBox1.Text.Trim());
}
}
}
为什么会提示我不可访问或受限制呢???谁明白,请告知!!!
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货