speech
All Data Structures Functions Modules Pages
main.cpp
1 /*
2  * AcaTTS Sample
3  *
4  * Copyright (c) 2010 Acapela Group
5  *
6  * All rights reserved.
7  * PERMISSION IS HEREBY DENIED TO USE, COPY, MODIFY, OR DISTRIBUTE THIS
8  * SOFTWARE OR ITS DOCUMENTATION FOR ANY PURPOSE WITHOUT WRITTEN
9  * AGREEMENT OR ROYALTY FEES.
10 */
11 
19 #include <string>
20 #include <iostream>
21 #include <iomanip>
22 #include <windows.h>
23 
24 #include "ioBabTts.h"
25 
26 #define _BABTTSDYN_IMPL_
27 #include "ifBabTtsDyn.h"
28 #undef _BABTTSDYN_IMPL_
29 
30 
31 int main(int argc, char *argv[])
32 {
33  std::string voice="iCub_eng";
34  if (argc>1)
35  voice=argv[1];
36 
37  std::cout<<"Voice is: "<<voice<<std::endl;
38 
39  std::string textInput;
40  std::getline(std::cin,textInput);
41  std::cout<<"Text is: "<<textInput<<std::endl;
42 
43  LPBABTTS lpEngine;
44  if (BabTtsInitDllEx(_T("."))==NULL)
45  {
46  std::cerr<<"Error: Could not load AcaTTS"<<std::endl;
47  exit(-1);
48  }
49 
50  if (!BabTTS_Init())
51  {
52  std::cerr<<"Error: Could not initialize AcaTTS"<<std::endl;
53  BabTtsUninitDll();
54  exit(-1);
55  }
56 
57  lpEngine=BabTTS_Create();
58  if (lpEngine==NULL)
59  {
60  std::cerr<<"Error: Could not create AcaTTS context"<<std::endl;
61  BabTTS_Uninit();
62  BabTtsUninitDll();
63  exit(-1);
64  }
65 
66  if (BabTTS_Open(lpEngine,voice.c_str(),0)!=E_BABTTS_NOERROR)
67  {
68  std::cerr<<"Error: Could not open "<<voice<<std::endl;
69  BabTTS_Close(lpEngine);
70  BabTTS_Uninit();
71  BabTtsUninitDll();
72  exit(-1);
73  }
74 
75  if (argc>2)
76  {
77  int speed=atoi(argv[2]);
78  BabTTS_SetSettings(lpEngine,BABTTS_PARAM_SPEED,speed);
79  }
80 
81  if (argc>3)
82  {
83  int pitchMultiplier=atoi(argv[3]);
84  BabTTS_SetSettings(lpEngine,BABTTS_PARAM_PITCH,pitchMultiplier);
85  }
86 
87  BabTTS_Speak(lpEngine,textInput.c_str(),BABTTS_SYNC|BABTTS_TAG_SAPI);
88 
89  BabTTS_Close(lpEngine);
90  BabTTS_Uninit();
91  BabTtsUninitDll();
92 
93  return 0;
94 }