Get it on Google Play


Wm뮤 :: 윈폼 TTS

블로그 이미지
가끔 그림그리거나 3D모델링하거나
취미로 로봇만드는
전자과 게임프로그래머 (퇴사함)
2022.3.22f1 주로 사용
모카쨩
@Ahzkwid

Recent Comment

Archive


2024. 7. 31. 01:06 윈도우폼

 

 

 

기본적으로 설치되어있으므로 필수는 아닌데 설치하면 좋다

 

 

 

 

 

 

 

 

 

https://github.com/ahzkwid/WindowVoice/blob/main/WindowVoice/Form1_main.cs

 

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

using System.Windows.Input;
using System.Speech.Synthesis;

namespace WindowVoice
{
    public partial class Form1_main : Form
    {
        private static SpeechSynthesizer synth = new SpeechSynthesizer();
        public Form1_main()
        {
            InitializeComponent();
            
            synth.SetOutputToDefaultAudioDevice();
            //synth.SelectVoice("Microsoft Server Speech Text to Speech Voice (ko-KR, Heami)");
            //synth.SelectVoice("Microsoft Server Speech Text to Speech Voice (ko-KR, TELE)");
            //synth.SelectVoiceByHints(VoiceGender.Male);
            //synth.SelectVoice("Microsoft Zira Desktop");
            //synth.SelectVoice("Microsoft Heami Desktop");

            textBox1_speech.KeyDown += new System.Windows.Forms.KeyEventHandler(this.key_down);
        }
        private void key_down(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Escape)//ESC눌렀을떄
            {
                textBox1_speech.Text = "";
            }
            if ((e.KeyCode == Keys.Enter || e.KeyCode == Keys.Return)) //엔터 눌렀을때
            {
                if (((Control.ModifierKeys & Keys.Alt) == Keys.Alt)) //알트눌려있을때
                {
                    int pos = textBox1_speech.SelectionStart;//텍스트박스 포인터 위치
                    textBox1_speech.Text += "\r\n"; //엔터추가 \r을 붙여야 연속추가가 되는듯
                    textBox1_speech.Select(pos + 2, 0); //텍스트박스 포인터 복구하고 엔터 길이만큼 이동
                }
                else
                {
                    e.SuppressKeyPress = true;//엔터무시
                    speech();
                    if (checkBox1_enter_to_clear.Checked == true) //엔터 누를떄 지우기 체크되어있을경우
                    {
                        textBox1_speech.Text = "";
                    }
                }
            }
        }
        private void speech()
        {
            if (textBox1_speech.Text == "문장 입력")
            {
                textBox1_speech.Text = "";
            }
            if (textBox1_speech.Text != "")
            {
                System.Threading.ThreadPool.QueueUserWorkItem(speech, textBox1_speech.Text); //스레드풀
                //speech(textBox1_speech.Text);
            }
        }
        private void speech(Object str)
        {
            synth.Speak((string)str);
        }
        private void speech(string str)
        {
            synth.Speak(str);
        }

        private void button1_enter_Click(object sender, EventArgs e)
        {
            speech();
        }
    }
}

'윈도우폼' 카테고리의 다른 글

C# NAudio  (0) 2024.07.31
윈폼 차트  (0) 2024.01.15
윈도우용 대화형 프로그램 설정  (0) 2023.09.26
posted by 모카쨩

저사양 유저용 블로그 진입