speech
Loading...
Searching...
No Matches
main.cpp
1/*
2* Copyright(C) 2015 Insitute For Infocomm Research, A*STAR, Singapore
3* Authors: Stephane Lallee
4* email : stephane.lallee@gmail.com
5* Permission is granted to copy, distribute, and / or modify this program
6* under the terms of the GNU General Public License, version 2 or any
7* later version published by the Free Software Foundation.
8*
9* A copy of the license can be found at
10* wysiwyd / license / gpl.txt
11*
12* This program is distributed in the hope that it will be useful, but
13* WITHOUT ANY WARRANTY; without even the implied warranty of
14* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the GNU General
15* Public License for more details
16*/
17
50#include "stdafx.h"
51
53//Helpers for dealing with the weird strings of windows...
54std::wstring s2ws(const std::string& s)
55{
56 int len;
57 int slength = (int)s.length() + 1;
58 len = MultiByteToWideChar(CP_ACP, 0, s.c_str(), slength, 0, 0);
59 wchar_t* buf = new wchar_t[len];
60 MultiByteToWideChar(CP_ACP, 0, s.c_str(), slength, buf, len);
61 std::wstring r(buf);
62 delete[] buf;
63 return r;
64}
65std::string ws2s(LPCWSTR s)
66{
67 char *pmbbuf = (char *)malloc(100);
68 wcstombs(pmbbuf, s, 100);
69 return pmbbuf;
70}
71
73
74int main(int argc, char* argv[])
75{
76 //Parse de parameters. Similar way to acapelaCmd
77 std::string voice = "iCub_eng";
78 if (argc>1)
79 voice = argv[1];
80 std::cout << "Voice is: " << voice << std::endl;
81 std::cout << "TODO : select the right token from this option." << voice << std::endl;
82
83 std::string textInput;
84 std::getline(std::cin, textInput);
85 std::cout << "Text is: " << textInput << std::endl;
86
87 if (::CoInitializeEx(NULL, COINIT_MULTITHREADED) == S_OK)
88 {
89 HRESULT hr = S_OK;
90 CComPtr<IEnumSpObjectTokens> cpIEnum;
91 CComPtr<ISpObjectToken> cpToken;
92 CComPtr<ISpVoice> cpVoice;
93
94 // Enumerate voice tokens that speak US English in a female voice.
95 hr = SpEnumTokens(SPCAT_VOICES, L"Language=409", L"Gender=Female;", &cpIEnum);
96
97 // Get the best matching token.
98 if (SUCCEEDED(hr))
99 {
100 hr = cpIEnum->Next(1, &cpToken , NULL);
101 }
102
103 // Create a voice and set its token to the one we just found.
104 if (SUCCEEDED(hr))
105 {
106 hr = cpVoice.CoCreateInstance(CLSID_SpVoice);
107 }
108
109 // Set the voice.
110 if (SUCCEEDED(hr))
111 {
112 hr = cpVoice->SetVoice(cpToken);
113 }
114
115 // Set the output to the default audio device.
116 if (SUCCEEDED(hr))
117 {
118 hr = cpVoice->SetOutput(NULL, TRUE);
119 }
120
121 // Speak a string directly.
122 if (SUCCEEDED(hr))
123 {
124 hr = cpVoice->Speak(s2ws(textInput).c_str(), NULL, NULL);
125 }
126 }
127 ::CoUninitialize();
128
129 return 0;
130}
131
132