質問編集履歴

3

誤字

2018/07/21 08:32

投稿

maeta
maeta

スコア12

test CHANGED
File without changes
test CHANGED
@@ -29,10 +29,6 @@
29
29
  TTSクラス
30
30
 
31
31
  ```Java
32
-
33
- package com.soppra.listv;
34
-
35
-
36
32
 
37
33
  import android.content.Context;
38
34
 

2

コード追加

2018/07/21 08:31

投稿

maeta
maeta

スコア12

test CHANGED
File without changes
test CHANGED
@@ -21,3 +21,141 @@
21
21
  つきまつまであとじゅうにち
22
22
 
23
23
  となってしまう。
24
+
25
+
26
+
27
+
28
+
29
+ TTSクラス
30
+
31
+ ```Java
32
+
33
+ package com.soppra.listv;
34
+
35
+
36
+
37
+ import android.content.Context;
38
+
39
+ import android.speech.tts.TextToSpeech;
40
+
41
+ import android.speech.tts.UtteranceProgressListener;
42
+
43
+
44
+
45
+ public class TTS {
46
+
47
+
48
+
49
+ private static TextToSpeech textToSpeech;
50
+
51
+ private static boolean chkSpeak = false;
52
+
53
+
54
+
55
+ public static void init(final Context context) {
56
+
57
+ if (textToSpeech == null) {
58
+
59
+ textToSpeech = new TextToSpeech(context, new TextToSpeech.OnInitListener() {
60
+
61
+ @Override
62
+
63
+ public void onInit(int i) {
64
+
65
+ chkSpeak = true;
66
+
67
+ }
68
+
69
+ });
70
+
71
+ }
72
+
73
+ }
74
+
75
+
76
+
77
+ public static void speak(final String text, final String utteranceld) {
78
+
79
+ textToSpeech.speak(text, TextToSpeech.QUEUE_FLUSH, null, utteranceld);
80
+
81
+ }
82
+
83
+
84
+
85
+ public static boolean isSpeaking() {
86
+
87
+ return textToSpeech.isSpeaking();
88
+
89
+ }
90
+
91
+
92
+
93
+ public static void killSpeaking(){
94
+
95
+ textToSpeech.stop();
96
+
97
+ }
98
+
99
+
100
+
101
+ public static void setOnUtteranceProgressListener(UtteranceProgressListener l) {
102
+
103
+ textToSpeech.setOnUtteranceProgressListener(l);
104
+
105
+ }
106
+
107
+ }
108
+
109
+ ```
110
+
111
+
112
+
113
+ MainActivity.java
114
+
115
+ ```Java
116
+
117
+
118
+
119
+ // TextToSpeechの初期化処理を行う。
120
+
121
+ TTS.init(getApplicationContext());
122
+
123
+
124
+
125
+ // TextToSpeechの読み上げ終了検知イベントリスナーを設定
126
+
127
+ TTS.setOnUtteranceProgressListener(new UtteranceProgressListener() {
128
+
129
+ @Override
130
+
131
+ public void onDone(String utteranceId) {
132
+
133
+ MainActivity.this.onTtsDone();
134
+
135
+ }
136
+
137
+
138
+
139
+ @Override
140
+
141
+ public void onError(String utteranceId) {}
142
+
143
+
144
+
145
+ @Override
146
+
147
+ public void onStart(String utteranceId) {}
148
+
149
+ });
150
+
151
+
152
+
153
+ String ssmlText = "<speak><sub alias=\"げつまつ\">月末</sub>まであと10日</speak>";
154
+
155
+
156
+
157
+ TTS.speak(ssmlText, this.hashCode() + "");
158
+
159
+
160
+
161
+ ```

1

誤字修正

2018/07/21 08:31

投稿

maeta
maeta

スコア12

test CHANGED
File without changes
test CHANGED
@@ -6,7 +6,7 @@
6
6
 
7
7
  その時にSSMLで読み方を指定したい。
8
8
 
9
- どうすればSSMLがいてくるのでしょうか?
9
+ どうすればSSMLがいてくるのでしょうか?
10
10
 
11
11
 
12
12