react-native-davoice-tts 1.0.218 → 1.0.220

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.
Files changed (35) hide show
  1. package/TTSRNBridge.podspec +1 -1
  2. package/ios/SpeechBridge/SpeechBridge.m +153 -0
  3. package/ios/TTSRNBridge/DavoiceTTS.xcframework/ios-arm64/DavoiceTTS.framework/DavoiceTTS +0 -0
  4. package/ios/TTSRNBridge/DavoiceTTS.xcframework/ios-arm64/DavoiceTTS.framework/Headers/DavoiceTTS-Swift.h +7 -0
  5. package/ios/TTSRNBridge/DavoiceTTS.xcframework/ios-arm64/DavoiceTTS.framework/Modules/DavoiceTTS.swiftmodule/arm64-apple-ios.abi.json +1324 -1238
  6. package/ios/TTSRNBridge/DavoiceTTS.xcframework/ios-arm64/DavoiceTTS.framework/Modules/DavoiceTTS.swiftmodule/arm64-apple-ios.private.swiftinterface +14 -12
  7. package/ios/TTSRNBridge/DavoiceTTS.xcframework/ios-arm64/DavoiceTTS.framework/Modules/DavoiceTTS.swiftmodule/arm64-apple-ios.swiftdoc +0 -0
  8. package/ios/TTSRNBridge/DavoiceTTS.xcframework/ios-arm64/DavoiceTTS.framework/Modules/DavoiceTTS.swiftmodule/arm64-apple-ios.swiftinterface +14 -12
  9. package/ios/TTSRNBridge/DavoiceTTS.xcframework/ios-arm64_x86_64-simulator/DavoiceTTS.framework/DavoiceTTS +0 -0
  10. package/ios/TTSRNBridge/DavoiceTTS.xcframework/ios-arm64_x86_64-simulator/DavoiceTTS.framework/Headers/DavoiceTTS-Swift.h +14 -0
  11. package/ios/TTSRNBridge/DavoiceTTS.xcframework/ios-arm64_x86_64-simulator/DavoiceTTS.framework/Modules/DavoiceTTS.swiftmodule/arm64-apple-ios-simulator.abi.json +3405 -3319
  12. package/ios/TTSRNBridge/DavoiceTTS.xcframework/ios-arm64_x86_64-simulator/DavoiceTTS.framework/Modules/DavoiceTTS.swiftmodule/arm64-apple-ios-simulator.private.swiftinterface +34 -32
  13. package/ios/TTSRNBridge/DavoiceTTS.xcframework/ios-arm64_x86_64-simulator/DavoiceTTS.framework/Modules/DavoiceTTS.swiftmodule/arm64-apple-ios-simulator.swiftdoc +0 -0
  14. package/ios/TTSRNBridge/DavoiceTTS.xcframework/ios-arm64_x86_64-simulator/DavoiceTTS.framework/Modules/DavoiceTTS.swiftmodule/arm64-apple-ios-simulator.swiftinterface +34 -32
  15. package/ios/TTSRNBridge/DavoiceTTS.xcframework/ios-arm64_x86_64-simulator/DavoiceTTS.framework/Modules/DavoiceTTS.swiftmodule/x86_64-apple-ios-simulator.abi.json +3405 -3319
  16. package/ios/TTSRNBridge/DavoiceTTS.xcframework/ios-arm64_x86_64-simulator/DavoiceTTS.framework/Modules/DavoiceTTS.swiftmodule/x86_64-apple-ios-simulator.private.swiftinterface +34 -32
  17. package/ios/TTSRNBridge/DavoiceTTS.xcframework/ios-arm64_x86_64-simulator/DavoiceTTS.framework/Modules/DavoiceTTS.swiftmodule/x86_64-apple-ios-simulator.swiftdoc +0 -0
  18. package/ios/TTSRNBridge/DavoiceTTS.xcframework/ios-arm64_x86_64-simulator/DavoiceTTS.framework/Modules/DavoiceTTS.swiftmodule/x86_64-apple-ios-simulator.swiftinterface +34 -32
  19. package/ios/TTSRNBridge/DavoiceTTS.xcframework/ios-arm64_x86_64-simulator/DavoiceTTS.framework/_CodeSignature/CodeDirectory +0 -0
  20. package/ios/TTSRNBridge/DavoiceTTS.xcframework/ios-arm64_x86_64-simulator/DavoiceTTS.framework/_CodeSignature/CodeRequirements-1 +0 -0
  21. package/ios/TTSRNBridge/DavoiceTTS.xcframework/ios-arm64_x86_64-simulator/DavoiceTTS.framework/_CodeSignature/CodeResources +33 -108
  22. package/package.json +1 -1
  23. package/speech/index.ts +106 -0
  24. package/android/src/main/java/com/davoice/tts/rn/DaVoiceTTSPackage.java_old_using_new_for_both_stt_and_tts +0 -26
  25. package/ios/STTRNBridge/STTBridge.m_wtf +0 -109
  26. package/ios/TTSRNBridge/DavoiceTTS.xcframework/ios-arm64/DavoiceTTS.framework/DaVoiceSTT copy.swift____ +0 -1202
  27. package/ios/TTSRNBridge/DavoiceTTS.xcframework/ios-arm64/DavoiceTTS.framework/DaVoiceSTT.swift.bkup +0 -1000
  28. package/ios/TTSRNBridge/DavoiceTTS.xcframework/ios-arm64/DavoiceTTS.framework/DaVoiceSTT.swift.latest +0 -1359
  29. package/ios/TTSRNBridge/DavoiceTTS.xcframework/ios-arm64/DavoiceTTS.framework/DaVoiceSTT.swift1.swift__ +0 -1134
  30. package/ios/TTSRNBridge/DavoiceTTS.xcframework/ios-arm64/DavoiceTTS.framework/DaVoiceSTT.swift__ +0 -1329
  31. package/ios/TTSRNBridge/DavoiceTTS.xcframework/ios-arm64_x86_64-simulator/DavoiceTTS.framework/DaVoiceSTT copy.swift____ +0 -1202
  32. package/ios/TTSRNBridge/DavoiceTTS.xcframework/ios-arm64_x86_64-simulator/DavoiceTTS.framework/DaVoiceSTT.swift.bkup +0 -1000
  33. package/ios/TTSRNBridge/DavoiceTTS.xcframework/ios-arm64_x86_64-simulator/DavoiceTTS.framework/DaVoiceSTT.swift.latest +0 -1359
  34. package/ios/TTSRNBridge/DavoiceTTS.xcframework/ios-arm64_x86_64-simulator/DavoiceTTS.framework/DaVoiceSTT.swift1.swift__ +0 -1134
  35. package/ios/TTSRNBridge/DavoiceTTS.xcframework/ios-arm64_x86_64-simulator/DavoiceTTS.framework/DaVoiceSTT.swift__ +0 -1329
@@ -2,7 +2,7 @@ require 'json'
2
2
 
3
3
  Pod::Spec.new do |s|
4
4
  s.name = "TTSRNBridge"
5
- s.version = "1.0.91" # Update to your package version
5
+ s.version = "1.0.93" # Update to your package version
6
6
  s.summary = "TTS for React Native."
7
7
  s.description = <<-DESC
8
8
  A React Native module for tts .
@@ -2,10 +2,102 @@
2
2
  #import "SpeechBridge.h"
3
3
  #import <React/RCTLog.h>
4
4
  #import <React/RCTConvert.h>
5
+ #import <AudioToolbox/AudioToolbox.h>
5
6
 
6
7
  // Import your Swift classes (names as in your project)
7
8
  #import <DaVoiceTTS/DaVoiceTTS-Swift.h> // DaVoiceTTS + STT live here in your setup
8
9
 
10
+
11
+ static NSData *SB_Base64Decode(NSString *b64) {
12
+ if (!b64 || (id)b64 == [NSNull null]) return nil;
13
+ return [[NSData alloc] initWithBase64EncodedString:b64 options:0];
14
+ }
15
+
16
+ // Make a mono Float32 AVAudioPCMBuffer from raw PCM payload (i16 or f32).
17
+ // We accept either interleaved or non-interleaved input and mixdown to mono
18
+ // (DaVoiceTTS.playBuffer will resample / normalize as needed).
19
+ static AVAudioPCMBuffer *SB_MakeMonoF32Buffer(NSData *raw,
20
+ double sampleRate,
21
+ NSString *fmt, // "i16" | "f32"
22
+ NSInteger channels, // >= 1
23
+ BOOL interleaved)
24
+ {
25
+ if (!raw || raw.length == 0 || channels < 1) return nil;
26
+
27
+ // Target: mono float32, non-interleaved
28
+ AVAudioFormat *dstFmt = [[AVAudioFormat alloc] initStandardFormatWithSampleRate:sampleRate channels:1];
29
+ NSUInteger frameCount = 0;
30
+
31
+ if ([fmt.lowercaseString isEqualToString:@"i16"]) {
32
+ // Each sample is 2 bytes
33
+ const NSUInteger bytesPerSample = 2;
34
+ if (raw.length % (bytesPerSample * channels) != 0) return nil;
35
+ frameCount = raw.length / (bytesPerSample * channels);
36
+
37
+ AVAudioPCMBuffer *buf = [[AVAudioPCMBuffer alloc] initWithPCMFormat:dstFmt frameCapacity:(AVAudioFrameCount)frameCount];
38
+ buf.frameLength = (AVAudioFrameCount)frameCount;
39
+
40
+ const int16_t *in = (const int16_t *)raw.bytes;
41
+ float *out = buf.floatChannelData[0];
42
+ const float scale = 1.0f / 32768.0f;
43
+
44
+ if (interleaved || channels == 1) {
45
+ // Interleaved: [c0,c1,.., c0,c1,..]
46
+ for (NSUInteger f = 0; f < frameCount; ++f) {
47
+ int64_t acc = 0;
48
+ for (NSInteger ch = 0; ch < channels; ++ch) {
49
+ acc += in[f*channels + ch];
50
+ }
51
+ out[f] = (float)(acc / (double)channels) * scale;
52
+ }
53
+ } else {
54
+ // Non-interleaved planar i16 (rare): [all c0][all c1]…
55
+ const NSUInteger planeLen = frameCount;
56
+ for (NSUInteger f = 0; f < frameCount; ++f) {
57
+ int64_t acc = 0;
58
+ for (NSInteger ch = 0; ch < channels; ++ch) {
59
+ acc += in[ch*planeLen + f];
60
+ }
61
+ out[f] = (float)(acc / (double)channels) * scale;
62
+ }
63
+ }
64
+ return buf;
65
+ }
66
+
67
+ // f32 path
68
+ if (![fmt.lowercaseString isEqualToString:@"f32"]) return nil;
69
+ const NSUInteger bytesPerSample = 4;
70
+ if (raw.length % (bytesPerSample * channels) != 0) return nil;
71
+ frameCount = raw.length / (bytesPerSample * channels);
72
+
73
+ AVAudioPCMBuffer *buf = [[AVAudioPCMBuffer alloc] initWithPCMFormat:dstFmt frameCapacity:(AVAudioFrameCount)frameCount];
74
+ buf.frameLength = (AVAudioFrameCount)frameCount;
75
+
76
+ const float *in = (const float *)raw.bytes;
77
+ float *out = buf.floatChannelData[0];
78
+
79
+ if (interleaved || channels == 1) {
80
+ for (NSUInteger f = 0; f < frameCount; ++f) {
81
+ double acc = 0.0;
82
+ for (NSInteger ch = 0; ch < channels; ++ch) {
83
+ acc += in[f*channels + ch];
84
+ }
85
+ out[f] = (float)(acc / (double)channels);
86
+ }
87
+ } else {
88
+ // Planar f32: [all c0][all c1]…
89
+ const NSUInteger planeLen = frameCount;
90
+ for (NSUInteger f = 0; f < frameCount; ++f) {
91
+ double acc = 0.0;
92
+ for (NSInteger ch = 0; ch < channels; ++ch) {
93
+ acc += in[ch*planeLen + f];
94
+ }
95
+ out[f] = (float)(acc / (double)channels);
96
+ }
97
+ }
98
+ return buf;
99
+ }
100
+
9
101
  @interface SpeechBridge () <STTDelegate>
10
102
  @property (nonatomic, strong, nullable) STT *stt;
11
103
  @property (nonatomic, strong, nullable) DaVoiceTTS *tts;
@@ -233,4 +325,65 @@ RCT_EXPORT_METHOD(stopSpeaking:(RCTPromiseResolveBlock)resolve
233
325
  resolve(@"Stopped");
234
326
  }
235
327
 
328
+ /// playWav(pathOrURL: string, markAsLast?: boolean)
329
+ RCT_EXPORT_METHOD(playWav:(NSString *)pathOrURL
330
+ markAsLast:(nonnull NSNumber *)markAsLast
331
+ resolver:(RCTPromiseResolveBlock)resolve
332
+ rejecter:(RCTPromiseRejectBlock)reject)
333
+ {
334
+ if (!self.tts) { reject(@"no_tts", @"Call initAll first", nil); return; }
335
+
336
+ NSURL *url = nil;
337
+ if ([pathOrURL hasPrefix:@"http://"] || [pathOrURL hasPrefix:@"https://"] || [pathOrURL hasPrefix:@"file://"]) {
338
+ url = [NSURL URLWithString:pathOrURL];
339
+ if (url.isFileURL == NO) {
340
+ // For remote URLs: you’d normally download first. Keep it simple: reject.
341
+ reject(@"unsupported_url", @"Remote URLs not supported. Download to a file path first.", nil);
342
+ return;
343
+ }
344
+ } else {
345
+ url = [NSURL fileURLWithPath:pathOrURL];
346
+ }
347
+
348
+ if (![[NSFileManager defaultManager] fileExistsAtPath:url.path]) {
349
+ reject(@"file_missing", @"WAV file does not exist at path", nil);
350
+ return;
351
+ }
352
+
353
+ // Pass through to DaVoiceTTS (which routes via AEC graph/queue)
354
+ [self.tts playWav:url markAsLastUtterance:markAsLast.boolValue];
355
+ resolve(@"queued");
356
+ }
357
+
358
+ /// playBuffer(desc: { base64, sampleRate, channels?, interleaved?, format: "i16" | "f32", markAsLast? })
359
+ RCT_EXPORT_METHOD(playBuffer:(NSDictionary *)desc
360
+ resolver:(RCTPromiseResolveBlock)resolve
361
+ rejecter:(RCTPromiseRejectBlock)reject)
362
+ {
363
+ if (!self.tts) { reject(@"no_tts", @"Call initAll first", nil); return; }
364
+
365
+ // Validate inputs
366
+ NSString *b64 = [RCTConvert NSString:desc[@"base64"]];
367
+ NSNumber *srN = [RCTConvert NSNumber:desc[@"sampleRate"]];
368
+ NSString *fmt = [RCTConvert NSString:desc[@"format"]];
369
+ NSNumber *chN = desc[@"channels"] ? [RCTConvert NSNumber:desc[@"channels"]] : @(1);
370
+ NSNumber *ilN = desc[@"interleaved"] ? [RCTConvert NSNumber:desc[@"interleaved"]] : @(YES);
371
+ NSNumber *markLastN = desc[@"markAsLast"] ? [RCTConvert NSNumber:desc[@"markAsLast"]] : @(YES);
372
+
373
+ if (!b64 || !srN || !fmt) {
374
+ reject(@"invalid_args", @"Missing one of base64/sampleRate/format", nil);
375
+ return;
376
+ }
377
+
378
+ NSData *raw = SB_Base64Decode(b64);
379
+ if (!raw) { reject(@"bad_base64", @"Could not decode base64 payload", nil); return; }
380
+
381
+ AVAudioPCMBuffer *buf = SB_MakeMonoF32Buffer(raw, srN.doubleValue, fmt, chN.integerValue, ilN.boolValue);
382
+ if (!buf) { reject(@"bad_buffer", @"Unsupported PCM layout or empty data", nil); return; }
383
+
384
+ // Hand over to DaVoiceTTS (it will resample/normalize and enqueue via AEC graph)
385
+ [self.tts playBuffer:buf markAsLastUtterance:markLastN.boolValue];
386
+ resolve(@"queued");
387
+ }
388
+
236
389
  @end
@@ -322,6 +322,13 @@ SWIFT_CLASS("_TtC10DavoiceTTS10DaVoiceTTS")
322
322
  - (void)destroy;
323
323
  - (void)speak:(NSString * _Nonnull)txt sid:(int32_t)sid;
324
324
  - (AVAudioPCMBuffer * _Nullable)synthesize_top:(NSString * _Nonnull)_text speakerId:(int32_t)speakerId token:(NSUUID * _Nonnull)token error:(NSError * _Nullable * _Nullable)error SWIFT_WARN_UNUSED_RESULT;
325
+ /// Queue an external WAV file for playback via the same AEC path/queue used by speak().
326
+ /// If called repeatedly, items are queued in order. <code>onLastUtteranceFinished</code> fires
327
+ /// after THIS file finishes (unless you enqueue more later and mark those as last).
328
+ - (void)playWav:(NSURL * _Nonnull)url markAsLastUtterance:(BOOL)markAsLastUtterance;
329
+ /// Queue an in-memory PCM buffer (any format) for playback via the same AEC path/queue.
330
+ /// We resample/normalize, write a temp WAV, then enqueue it (so it uses the engine hook).
331
+ - (void)playBuffer:(AVAudioPCMBuffer * _Nonnull)buffer markAsLastUtterance:(BOOL)markAsLastUtterance;
325
332
  - (nonnull instancetype)init SWIFT_UNAVAILABLE;
326
333
  + (nonnull instancetype)new SWIFT_UNAVAILABLE_MSG("-init is unavailable");
327
334
  @end