Skip to content

Commit ebb2348

Browse files
committed
Added VoiceComposer & VoiceComposition.
1 parent 7a75d44 commit ebb2348

4 files changed

Lines changed: 255 additions & 8 deletions

File tree

api/astive-menu/src/main/java/com/phonytive/astive/menu/MenuItem.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import com.phonytive.astive.menu.action.Action;
2323
import com.phonytive.astive.menu.event.*;
2424
import java.util.ArrayList;
25+
import java.util.List;
2526

2627
/**
2728
*
@@ -44,12 +45,14 @@ public class MenuItem {
4445
private String file;
4546
private boolean forgetAuthOnLeave = false;
4647
private boolean mustAuthenticate;
47-
private int priority;
48+
private int priority;
49+
private List<VoiceComposition> voiceCompositionList;
4850

4951
/**
5052
* <p>Creates a new instance of MenuItem</p>
5153
*/
5254
public MenuItem() {
55+
voiceCompositionList = new ArrayList<VoiceComposition>();
5356
}
5457

5558
/**
@@ -59,6 +62,7 @@ public MenuItem(String digits, String file) {
5962
//this.parent = parent;
6063
this.digits = digits;
6164
this.file = file;
65+
voiceCompositionList = new ArrayList<VoiceComposition>();
6266
}
6367

6468
/**
@@ -69,6 +73,7 @@ public MenuItem(String digits, String file, Action action) {
6973
this.digits = digits;
7074
this.file = file;
7175
this.action = action;
76+
voiceCompositionList = new ArrayList<VoiceComposition>();
7277
}
7378

7479
/**
@@ -80,6 +85,7 @@ public MenuItem(String digits, String file, Action action, int priority) {
8085
this.file = file;
8186
this.action = action;
8287
this.priority = priority;
88+
voiceCompositionList = new ArrayList<VoiceComposition>();
8389
}
8490

8591
/**
@@ -109,6 +115,18 @@ public void addDigitsListener(DigitsListener listener) {
109115
digitsListenerList.add(listener);
110116
}
111117

118+
/**
119+
*
120+
* @param voiceComposition
121+
*/
122+
public void addVoiceComposition(VoiceComposition voiceComposition) {
123+
voiceCompositionList.add(voiceComposition);
124+
}
125+
126+
public List<VoiceComposition> getVoiceCompositions() {
127+
return voiceCompositionList;
128+
}
129+
112130
/**
113131
* DOCUMENT ME!
114132
*

api/astive-menu/src/main/java/com/phonytive/astive/menu/MenuNavigator.java

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,7 @@
2323
import com.phonytive.astive.agi.AgiResponse;
2424
import com.phonytive.astive.menu.action.Action;
2525
import com.phonytive.astive.menu.event.*;
26-
import java.util.ArrayList;
27-
import java.util.Arrays;
28-
import java.util.Comparator;
26+
import java.util.*;
2927
import org.apache.log4j.Logger;
3028

3129
/**
@@ -139,8 +137,6 @@ private String getData(String file, int milliSecondsWatting, int maxDigits,
139137

140138
if (c != 0x0) {
141139
result += ("" + c);
142-
143-
144140
evt = new KeyEvent(item, Digit.getDigit("" + c));
145141
item.fireKeyEvent_keyTyped(evt);
146142
} else {
@@ -272,8 +268,25 @@ public void run(Menu menu) throws MenuException, AgiException {
272268

273269
msw = millisecondsWatting;
274270

275-
digits = getData(option.getFile(), msw, menu.getMaxDigits(), agiResponse,
276-
menu);
271+
272+
if(!option.getFile().isEmpty()) {
273+
digits = getData(option.getFile(), msw, menu.getMaxDigits(), agiResponse,
274+
menu);
275+
}
276+
277+
if ((digits != null) && !digits.equals("(timeout)")) {
278+
List<VoiceComposition> voiceCompositions = menu.getVoiceCompositions();
279+
Iterator<VoiceComposition> vcIterator = voiceCompositions.iterator();
280+
while(vcIterator.hasNext()) {
281+
VoiceComposition cVc = vcIterator.next();
282+
Iterator<Object> commands = cVc.getCommands().iterator();
283+
284+
while(commands.hasNext()) {
285+
Object o = commands.next();
286+
287+
}
288+
}
289+
}
277290
}
278291

279292
if ((digits != null) && !digits.equals("(timeout)")) {
Lines changed: 173 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
/*
2+
* Copyright (C) 2010-2012 PhonyTive LLC
3+
* http://astive.phonytive.com
4+
*
5+
* This file is part of Astive Toolkit
6+
*
7+
* Astive is free software: you can redistribute it and/or modify
8+
* it under the terms of the GNU General Public License as published by
9+
* the Free Software Foundation, either version 3 of the License, or
10+
* (at your option) any later version.
11+
*
12+
* Astive is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU General Public License
18+
* along with Astive. If not, see <http://www.gnu.org/licenses/>.
19+
*/
20+
package com.phonytive.astive.menu;
21+
22+
import com.phonytive.astive.agi.command.*;
23+
import java.util.ArrayList;
24+
import java.util.Date;
25+
import java.util.TimeZone;
26+
27+
/**
28+
*
29+
* @since 1.0.0
30+
*/
31+
public class VoiceComposer {
32+
33+
private static ArrayList<Object> commands;
34+
private static String escapeDigits;
35+
private static String format;
36+
private static TimeZone timeZone;
37+
private static VoiceComposer instance = new VoiceComposer();
38+
39+
private static void reset() {
40+
VoiceComposer.escapeDigits = "";
41+
VoiceComposer.commands = new ArrayList();
42+
VoiceComposer.format = "";
43+
VoiceComposer.timeZone = null;
44+
}
45+
46+
private VoiceComposer() {
47+
// hide the constructor
48+
commands = new ArrayList();
49+
}
50+
51+
public static VoiceComposer withEscapeDigits(String escapeDigits) {
52+
VoiceComposer.escapeDigits = escapeDigits;
53+
return instance;
54+
}
55+
56+
public static VoiceComposer withFormat(String format) {
57+
VoiceComposer.format = format;
58+
return instance;
59+
}
60+
61+
public static VoiceComposer withTimeZone(TimeZone timeZone) {
62+
VoiceComposer.timeZone = timeZone;
63+
return instance;
64+
}
65+
66+
public static VoiceComposer streamFile(String file) {
67+
if (hasEscapeDigits()) {
68+
commands.add(new StreamFile(file, VoiceComposer.escapeDigits));
69+
} else {
70+
commands.add(new StreamFile(file));
71+
}
72+
return instance;
73+
}
74+
75+
public static VoiceComposer sayAlpha(String text) {
76+
if (hasEscapeDigits()) {
77+
commands.add(new SayAlpha(text, VoiceComposer.escapeDigits));
78+
} else {
79+
commands.add(new SayAlpha(text));
80+
}
81+
return instance;
82+
}
83+
84+
public static VoiceComposer sayDate(Date date) {
85+
if (hasEscapeDigits()) {
86+
commands.add(new SayDate(date, VoiceComposer.escapeDigits));
87+
} else {
88+
commands.add(new SayDate(date));
89+
}
90+
return instance;
91+
}
92+
93+
public static VoiceComposer sayDatetime(Date datetime) {
94+
if (hasEscapeDigits()) {
95+
commands.add(new SayDatetime(datetime, VoiceComposer.escapeDigits));
96+
} else {
97+
commands.add(new SayDatetime(datetime));
98+
}
99+
return instance;
100+
}
101+
102+
public static VoiceComposer sayDigits(String digits) {
103+
if (hasEscapeDigits()) {
104+
commands.add(new SayDigits(digits, VoiceComposer.escapeDigits));
105+
} else {
106+
commands.add(new SayDigits(digits));
107+
}
108+
return instance;
109+
}
110+
111+
public static VoiceComposer sayNumber(int number) {
112+
if (hasEscapeDigits()) {
113+
commands.add(new SayNumber(number, VoiceComposer.escapeDigits));
114+
} else {
115+
commands.add(new SayNumber(number));
116+
}
117+
return instance;
118+
}
119+
120+
public static VoiceComposer sayPhonetic(String text) {
121+
if (hasEscapeDigits()) {
122+
commands.add(new SayPhonetic(text, VoiceComposer.escapeDigits));
123+
} else {
124+
commands.add(new SayPhonetic(text));
125+
}
126+
return instance;
127+
}
128+
129+
public static VoiceComposer sayTime(Date time) {
130+
if (hasEscapeDigits()) {
131+
commands.add(new SayTime(time, VoiceComposer.escapeDigits));
132+
} else {
133+
commands.add(new SayTime(time));
134+
}
135+
return instance;
136+
}
137+
138+
public static VoiceComposer addSilence(int silence) {
139+
if (hasEscapeDigits()) {
140+
commands.add(new StreamFile("silence/" + silence, VoiceComposer.escapeDigits));
141+
} else {
142+
commands.add(new StreamFile("silence/" + silence));
143+
}
144+
return instance;
145+
}
146+
147+
private static boolean hasEscapeDigits() {
148+
if (escapeDigits != null && escapeDigits.length() != 0) {
149+
return true;
150+
}
151+
return false;
152+
}
153+
154+
private static boolean hasFormat() {
155+
if (VoiceComposer.format != null) {
156+
return true;
157+
}
158+
return false;
159+
}
160+
161+
private static boolean hasTimeZone() {
162+
if (VoiceComposer.timeZone != null) {
163+
return true;
164+
}
165+
return false;
166+
}
167+
168+
public static VoiceComposition create() {
169+
VoiceComposition vc = new VoiceComposition(VoiceComposer.commands);
170+
VoiceComposer.reset();
171+
return vc;
172+
}
173+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* Copyright (C) 2010-2012 PhonyTive LLC
3+
* http://astive.phonytive.com
4+
*
5+
* This file is part of Astive Toolkit
6+
*
7+
* Astive is free software: you can redistribute it and/or modify
8+
* it under the terms of the GNU General Public License as published by
9+
* the Free Software Foundation, either version 3 of the License, or
10+
* (at your option) any later version.
11+
*
12+
* Astive is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU General Public License
18+
* along with Astive. If not, see <http://www.gnu.org/licenses/>.
19+
*/
20+
package com.phonytive.astive.menu;
21+
22+
import java.util.List;
23+
24+
/**
25+
*
26+
* @since 1.0.0
27+
*/
28+
public class VoiceComposition {
29+
30+
private List<Object> commands;
31+
32+
public VoiceComposition(List<Object> commands) {
33+
this.commands = commands;
34+
}
35+
36+
public List<Object> getCommands() {
37+
return commands;
38+
}
39+
40+
public void setCommands(List<Object> commands) {
41+
this.commands = commands;
42+
}
43+
}

0 commit comments

Comments
 (0)