@capgo/capacitor-speech-synthesis 8.0.4 → 8.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -23,7 +23,7 @@ import org.json.JSONException;
|
|
|
23
23
|
@CapacitorPlugin(name = "SpeechSynthesis")
|
|
24
24
|
public class SpeechSynthesisPlugin extends Plugin {
|
|
25
25
|
|
|
26
|
-
private final String pluginVersion = "8.0.
|
|
26
|
+
private final String pluginVersion = "8.0.5";
|
|
27
27
|
private TextToSpeech tts;
|
|
28
28
|
private int utteranceIdCounter = 0;
|
|
29
29
|
private boolean ttsInitialized = false;
|
|
@@ -7,7 +7,7 @@ import AVFoundation
|
|
|
7
7
|
*/
|
|
8
8
|
@objc(SpeechSynthesisPlugin)
|
|
9
9
|
public class SpeechSynthesisPlugin: CAPPlugin, CAPBridgedPlugin, AVSpeechSynthesizerDelegate {
|
|
10
|
-
private let pluginVersion: String = "8.0.
|
|
10
|
+
private let pluginVersion: String = "8.0.5"
|
|
11
11
|
public let identifier = "SpeechSynthesisPlugin"
|
|
12
12
|
public let jsName = "SpeechSynthesis"
|
|
13
13
|
public let pluginMethods: [CAPPluginMethod] = [
|
|
@@ -122,32 +122,28 @@ public class SpeechSynthesisPlugin: CAPPlugin, CAPBridgedPlugin, AVSpeechSynthes
|
|
|
122
122
|
}
|
|
123
123
|
|
|
124
124
|
// Write to file
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
}
|
|
125
|
+
let documentsPath = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)[0]
|
|
126
|
+
let audioFilename = documentsPath.appendingPathComponent("\(utteranceId).caf")
|
|
127
|
+
|
|
128
|
+
synthesizer?.write(utterance) { (buffer: AVAudioBuffer) in
|
|
129
|
+
guard let pcmBuffer = buffer as? AVAudioPCMBuffer else {
|
|
130
|
+
call.reject("Failed to get PCM buffer")
|
|
131
|
+
return
|
|
132
|
+
}
|
|
134
133
|
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
}
|
|
145
|
-
} else {
|
|
146
|
-
call.reject("Failed to create audio file")
|
|
134
|
+
if let audioFile = try? AVAudioFile(forWriting: audioFilename, settings: pcmBuffer.format.settings) {
|
|
135
|
+
do {
|
|
136
|
+
try audioFile.write(from: pcmBuffer)
|
|
137
|
+
call.resolve([
|
|
138
|
+
"filePath": audioFilename.path,
|
|
139
|
+
"utteranceId": utteranceId
|
|
140
|
+
])
|
|
141
|
+
} catch {
|
|
142
|
+
call.reject("Failed to write audio file: \(error.localizedDescription)")
|
|
147
143
|
}
|
|
144
|
+
} else {
|
|
145
|
+
call.reject("Failed to create audio file")
|
|
148
146
|
}
|
|
149
|
-
} else {
|
|
150
|
-
call.reject("synthesizeToFile requires iOS 13.0 or later")
|
|
151
147
|
}
|
|
152
148
|
}
|
|
153
149
|
|
|
@@ -189,24 +185,20 @@ public class SpeechSynthesisPlugin: CAPPlugin, CAPBridgedPlugin, AVSpeechSynthes
|
|
|
189
185
|
"language": voice.language
|
|
190
186
|
]
|
|
191
187
|
|
|
192
|
-
// Add gender
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
info["gender"] = "neutral"
|
|
201
|
-
}
|
|
188
|
+
// Add gender
|
|
189
|
+
switch voice.gender {
|
|
190
|
+
case .male:
|
|
191
|
+
info["gender"] = "male"
|
|
192
|
+
case .female:
|
|
193
|
+
info["gender"] = "female"
|
|
194
|
+
default:
|
|
195
|
+
info["gender"] = "neutral"
|
|
202
196
|
}
|
|
203
197
|
|
|
204
198
|
// Add network requirement
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
info["isNetworkConnectionRequired"] = voice.quality.rawValue < 2
|
|
209
|
-
}
|
|
199
|
+
// Higher quality voices (enhanced/premium) typically don't require network
|
|
200
|
+
// Default quality = 1, Enhanced quality = 2
|
|
201
|
+
info["isNetworkConnectionRequired"] = voice.quality.rawValue < 2
|
|
210
202
|
|
|
211
203
|
return info
|
|
212
204
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@capgo/capacitor-speech-synthesis",
|
|
3
|
-
"version": "8.0.
|
|
3
|
+
"version": "8.0.5",
|
|
4
4
|
"description": "Synthesize speech from text with full control over language, voice, pitch, rate, and volume.",
|
|
5
5
|
"main": "dist/plugin.cjs.js",
|
|
6
6
|
"module": "dist/esm/index.js",
|