简体   繁体   English

我无法使用 C# 表单(SpVoice)停止声音

[英]I can't stop sound with C# Form(SpVoice)

I'm developing a dictionary.我正在开发字典。 I can listening for words in dictionary.我可以听字典中的单词。 if we quickly listening a lot of words.如果我们很快听了很多话。 without listening the old words I cannot listen the currently selected word.不听旧词我听不到当前选择的词。 So I am waiting listen to the selected word.所以我在等着听选定的词。 ''' '''

class Voicer1
{
    public string read;
    public SpVoice Sound_SV = new SpVoice();
    public Thread th_WP;
    public void Sound_Stp(string vocalist)
    {           
        read = vocalist.ToString();
        thread_Stp();
    }
    public void thread_Stp()
    {
        th_WP = new Thread(new ThreadStart(sound_1));
        th_WP.Start();               
    }
    public void sound_1()
    {           
        Sound_SV.Speak(read.ToString(), SpeechVoiceSpeakFlags.SVSFDefault);
        GC.Collect();
        GC.WaitForPendingFinalizers();
    }
 }

This is listening这是在听

 Voicer1 Sound_1= new Voicer1();
Snd.Sound_Stp(label1.Text.ToString());

I use where necessary;我在必要时使用;

SoundPlayer stoprrr= new SoundPlayer();
stoprrr.Stop();

But this doesn't work.但这不起作用。

Can you help me你能帮助我吗

I use;我用; using System.Speech.Synthesis; then, SpeechSynthesizer SSObj;然后, SpeechSynthesizer SSObj; When I want to listen to the new word,当我想听新词时,

    if (SSObj!= null)
    {
        SSObj.Dispose();
    }

SSObj= new SpeechSynthesizer();
SSObj.SpeakAsync(read);

This method worked.这种方法奏效了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM