C++ Text-to-speech using Speech Synthesizer object

Aug 7, 2016 at 2:16pm
I’m beginner, need help

I’m just trying figure out with Text to Speech C++ in Visual Studio 2015 on Windows 10 using Speech Synthesizer object from this lesson https://youtu.be/YWRvd2j0HXY

So MyForm.h content to read from textbox:

1
2
3
4
5
6
7
8
    using namespace System::Speech::Synthesis;

    	private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
    
    		SpeechSynthesizer^synth=gcnew SpeechSynthesizer();
    		synth->Speak(textBox1->Text);
    	}
  


It works as given application and I want use it for Windows GUI too, but in this case my question is how to use it in different code without interface textbox, but just read text from variable value etc., because I can’t understand how to use it this way from given code. Some working examples, links of advice on this direction would be very helpful

Also I'm interested, if it possible to change male voice on female

Last edited on Aug 7, 2016 at 2:22pm
Aug 7, 2016 at 3:05pm
Iam not sure what you want to do.
1
2
SpeechSynthesizer^synth=gcnew SpeechSynthesizer();
synth->Speak("Any Text");

It does not matter where the text comes from. synth->Speak will speak a String^ var

http://www.codeproject.com/Articles/28725/A-Very-Easy-Introduction-to-Microsoft-NET-Speech-S
Also I'm interested, if it possible to change male voice on female

https://msdn.microsoft.com/en-us/library/system.speech.synthesis.speechsynthesizer.selectvoice(v=vs.110).aspx
https://msdn.microsoft.com/en-us/library/ms586869(v=vs.110).aspx
Aug 7, 2016 at 3:56pm
Hello, thank you for feedback, yes works this way, but two thing unclear, first how to read string from variable with changing value, for example if I have variable, which takes random words from text document? and how to call this tool in cpp document, because now it is in MyForm.h?
Last edited on Aug 7, 2016 at 3:58pm
Aug 7, 2016 at 5:35pm
You create the SpeechSynthesizer the same way as in a form.
1
2
3
4
5
using namespace System::Speech::Synthesis;
using namespace System::IO;

SpeechSynthesizer^ synth = gcnew SpeechSynthesizer();
synth->Speak("Any Text");


Let's say you have a file called words.txt
You can read it into an array with File::ReadAllLines() and then you pass a word from the array to the SpeechSynthesizer
Aug 7, 2016 at 5:59pm
Seems I'm doing something wrong, everything is undefined, using namespace System::Speech::Synthesis; shows: "name followed by '::' must be class of namespace name", SpeechSynthesizer^ synth = gcnew SpeechSynthesizer(); shows: "identifer "SpeechSynthesizer" is undefined" and "expected a 'a'", so what I have to do to fix this errors

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include "stdafx.h"
#include <conio.h>
#include <iostream>

using namespace System;

using namespace System::Speech::Synthesis;
using namespace System::IO;

int main()
{

    SpeechSynthesizer^ synth = gcnew SpeechSynthesizer();
    synth->Speak("Any Text");

    _getch();
    return 0;
}
}
Last edited on Aug 7, 2016 at 11:41pm
Aug 7, 2016 at 8:01pm
Did you create a CLR Console app ?
Aug 7, 2016 at 11:47pm
Yes problem was with References / System.Speech now works but I'm still can't figure out how to get string from variable, here is new question http://www.cplusplus.com/forum/beginner/195555/
Last edited on Aug 8, 2016 at 2:06am
Topic archived. No new replies allowed.