@chat21/chat21-web-widget 5.1.33 → 5.1.34-rc1

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 (201) hide show
  1. package/.angular-mcp-cache/package.json +1 -0
  2. package/.cursor/angular18-accessibility-auditor-skill.md +442 -0
  3. package/.cursor/mcp.json +15 -0
  4. package/.github/workflows/docker-community-push-latest.yml +23 -13
  5. package/.github/workflows/docker-image-tag-community-tag-push.yml +22 -12
  6. package/.github/workflows/playwright.yml +27 -0
  7. package/CHANGELOG.md +130 -6
  8. package/Dockerfile +4 -5
  9. package/angular.json +24 -4
  10. package/docs/changelog/this-branch.md +36 -0
  11. package/env.sample +3 -2
  12. package/mocks/voice-websocket-mock/server.cjs +245 -0
  13. package/nginx.conf +22 -2
  14. package/package.json +10 -3
  15. package/playwright.config.ts +41 -0
  16. package/src/app/app.component.html +2 -2
  17. package/src/app/app.component.scss +25 -14
  18. package/src/app/app.component.spec.ts +21 -6
  19. package/src/app/app.component.ts +10 -9
  20. package/src/app/app.module.ts +15 -0
  21. package/src/app/component/conversation-detail/conversation/conversation.component.html +25 -11
  22. package/src/app/component/conversation-detail/conversation/conversation.component.scss +40 -2
  23. package/src/app/component/conversation-detail/conversation/conversation.component.spec.ts +644 -75
  24. package/src/app/component/conversation-detail/conversation/conversation.component.ts +100 -14
  25. package/src/app/component/conversation-detail/conversation-audio-recorder/conversation-audio-recorder.component.html +25 -13
  26. package/src/app/component/conversation-detail/conversation-audio-recorder/conversation-audio-recorder.component.spec.ts +123 -5
  27. package/src/app/component/conversation-detail/conversation-audio-recorder/conversation-audio-recorder.component.ts +1 -0
  28. package/src/app/component/conversation-detail/conversation-content/conversation-content.component.html +23 -10
  29. package/src/app/component/conversation-detail/conversation-content/conversation-content.component.scss +33 -2
  30. package/src/app/component/conversation-detail/conversation-content/conversation-content.component.spec.ts +242 -149
  31. package/src/app/component/conversation-detail/conversation-content/conversation-content.component.ts +8 -6
  32. package/src/app/component/conversation-detail/conversation-emojii/conversation-emojii.component.spec.ts +53 -3
  33. package/src/app/component/conversation-detail/conversation-footer/conversation-footer.component.html +200 -96
  34. package/src/app/component/conversation-detail/conversation-footer/conversation-footer.component.scss +211 -6
  35. package/src/app/component/conversation-detail/conversation-footer/conversation-footer.component.spec.ts +452 -78
  36. package/src/app/component/conversation-detail/conversation-footer/conversation-footer.component.ts +291 -76
  37. package/src/app/component/conversation-detail/conversation-header/conversation-header.component.html +113 -53
  38. package/src/app/component/conversation-detail/conversation-header/conversation-header.component.scss +12 -4
  39. package/src/app/component/conversation-detail/conversation-header/conversation-header.component.spec.ts +274 -29
  40. package/src/app/component/conversation-detail/conversation-internal-frame/conversation-internal-frame.component.html +23 -9
  41. package/src/app/component/conversation-detail/conversation-internal-frame/conversation-internal-frame.component.spec.ts +80 -8
  42. package/src/app/component/conversation-detail/conversation-preview/conversation-preview.component.html +29 -23
  43. package/src/app/component/conversation-detail/conversation-preview/conversation-preview.component.spec.ts +185 -16
  44. package/src/app/component/conversation-detail/conversation-preview/conversation-preview.component.ts +34 -14
  45. package/src/app/component/conversation-detail/stream-audio-spectrum/stream-audio-spectrum.component.html +46 -0
  46. package/src/app/component/conversation-detail/stream-audio-spectrum/stream-audio-spectrum.component.scss +83 -0
  47. package/src/app/component/conversation-detail/stream-audio-spectrum/stream-audio-spectrum.component.ts +192 -0
  48. package/src/app/component/error-alert/error-alert.component.spec.ts +65 -5
  49. package/src/app/component/eyeeye-catcher-card/eyeeye-catcher-card.component.html +16 -7
  50. package/src/app/component/eyeeye-catcher-card/eyeeye-catcher-card.component.scss +21 -0
  51. package/src/app/component/eyeeye-catcher-card/eyeeye-catcher-card.component.spec.ts +89 -7
  52. package/src/app/component/form/form-builder/form-builder.component.html +1 -1
  53. package/src/app/component/form/form-builder/form-builder.component.spec.ts +163 -21
  54. package/src/app/component/form/inputs/form-checkbox/form-checkbox.component.html +8 -4
  55. package/src/app/component/form/inputs/form-checkbox/form-checkbox.component.scss +10 -5
  56. package/src/app/component/form/inputs/form-checkbox/form-checkbox.component.spec.ts +90 -16
  57. package/src/app/component/form/inputs/form-checkbox/form-checkbox.component.ts +26 -0
  58. package/src/app/component/form/inputs/form-label/form-label.component.spec.ts +45 -11
  59. package/src/app/component/form/inputs/form-radio-button/form-radio-button.component.spec.ts +24 -6
  60. package/src/app/component/form/inputs/form-select/form-select.component.spec.ts +14 -5
  61. package/src/app/component/form/inputs/form-text/form-text.component.html +14 -12
  62. package/src/app/component/form/inputs/form-text/form-text.component.scss +11 -1
  63. package/src/app/component/form/inputs/form-text/form-text.component.spec.ts +113 -17
  64. package/src/app/component/form/inputs/form-text/form-text.component.ts +35 -3
  65. package/src/app/component/form/inputs/form-textarea/form-textarea.component.html +13 -11
  66. package/src/app/component/form/inputs/form-textarea/form-textarea.component.scss +6 -5
  67. package/src/app/component/form/inputs/form-textarea/form-textarea.component.spec.ts +149 -13
  68. package/src/app/component/form/inputs/form-textarea/form-textarea.component.ts +26 -0
  69. package/src/app/component/form/prechat-form/prechat-form.component.html +14 -11
  70. package/src/app/component/form/prechat-form/prechat-form.component.spec.ts +102 -10
  71. package/src/app/component/form/prechat-form/prechat-form.component.ts +8 -1
  72. package/src/app/component/form/prechat-form-test-mock.ts +35 -0
  73. package/src/app/component/home/home.component.html +38 -31
  74. package/src/app/component/home/home.component.scss +4 -2
  75. package/src/app/component/home/home.component.spec.ts +226 -11
  76. package/src/app/component/home-conversations/home-conversations.component.html +30 -26
  77. package/src/app/component/home-conversations/home-conversations.component.scss +3 -0
  78. package/src/app/component/home-conversations/home-conversations.component.spec.ts +212 -36
  79. package/src/app/component/last-message/last-message.component.html +15 -9
  80. package/src/app/component/last-message/last-message.component.scss +16 -2
  81. package/src/app/component/last-message/last-message.component.spec.ts +204 -23
  82. package/src/app/component/last-message/last-message.component.ts +4 -1
  83. package/src/app/component/launcher-button/launcher-button.component.html +8 -13
  84. package/src/app/component/launcher-button/launcher-button.component.spec.ts +104 -8
  85. package/src/app/component/list-all-conversations/list-all-conversations.component.html +12 -17
  86. package/src/app/component/list-all-conversations/list-all-conversations.component.scss +2 -0
  87. package/src/app/component/list-conversations/list-conversations.component.html +22 -22
  88. package/src/app/component/menu-options/menu-options.component.html +30 -20
  89. package/src/app/component/menu-options/menu-options.component.spec.ts +125 -9
  90. package/src/app/component/message/audio/audio.component.html +13 -15
  91. package/src/app/component/message/audio/audio.component.spec.ts +140 -5
  92. package/src/app/component/message/audio/audio.component.ts +1 -5
  93. package/src/app/component/message/audio-sync/audio-sync.component.html +18 -0
  94. package/src/app/component/message/audio-sync/audio-sync.component.scss +65 -0
  95. package/src/app/component/message/audio-sync/audio-sync.component.spec.ts +103 -0
  96. package/src/app/component/message/audio-sync/audio-sync.component.ts +643 -0
  97. package/src/app/component/message/avatar/avatar.component.html +2 -2
  98. package/src/app/component/message/avatar/avatar.component.spec.ts +99 -7
  99. package/src/app/component/message/bubble-message/bubble-message.component.html +43 -51
  100. package/src/app/component/message/bubble-message/bubble-message.component.scss +59 -1
  101. package/src/app/component/message/bubble-message/bubble-message.component.spec.ts +154 -57
  102. package/src/app/component/message/bubble-message/bubble-message.component.ts +152 -109
  103. package/src/app/component/message/buttons/action-button/action-button.component.html +3 -4
  104. package/src/app/component/message/buttons/action-button/action-button.component.spec.ts +49 -5
  105. package/src/app/component/message/buttons/link-button/link-button.component.scss +5 -8
  106. package/src/app/component/message/buttons/link-button/link-button.component.spec.ts +50 -5
  107. package/src/app/component/message/buttons/text-button/text-button.component.spec.ts +44 -5
  108. package/src/app/component/message/carousel/carousel.component.html +29 -16
  109. package/src/app/component/message/carousel/carousel.component.scss +20 -8
  110. package/src/app/component/message/carousel/carousel.component.spec.ts +80 -3
  111. package/src/app/component/message/carousel/carousel.component.ts +16 -0
  112. package/src/app/component/message/frame/frame.component.html +9 -4
  113. package/src/app/component/message/frame/frame.component.spec.ts +34 -15
  114. package/src/app/component/message/frame/frame.component.ts +7 -2
  115. package/src/app/component/message/html/html.component.html +1 -1
  116. package/src/app/component/message/html/html.component.scss +1 -1
  117. package/src/app/component/message/html/html.component.spec.ts +24 -7
  118. package/src/app/component/message/image/image.component.html +12 -10
  119. package/src/app/component/message/image/image.component.scss +16 -0
  120. package/src/app/component/message/image/image.component.spec.ts +101 -15
  121. package/src/app/component/message/image/image.component.ts +90 -51
  122. package/src/app/component/message/info-message/info-message.component.spec.ts +26 -14
  123. package/src/app/component/message/json-sources/json-sources.component.html +38 -0
  124. package/src/app/component/message/json-sources/json-sources.component.scss +201 -0
  125. package/src/app/component/message/json-sources/json-sources.component.ts +89 -0
  126. package/src/app/component/message/like-unlike/like-unlike.component.html +7 -9
  127. package/src/app/component/message/like-unlike/like-unlike.component.spec.ts +31 -3
  128. package/src/app/component/message/return-receipt/return-receipt.component.spec.ts +38 -17
  129. package/src/app/component/message/text/text.component.html +3 -3
  130. package/src/app/component/message/text/text.component.scss +80 -86
  131. package/src/app/component/message/text/text.component.spec.ts +106 -13
  132. package/src/app/component/message-attachment/message-attachment.component.spec.ts +134 -13
  133. package/src/app/component/selection-department/selection-department.component.html +21 -23
  134. package/src/app/component/selection-department/selection-department.component.spec.ts +159 -14
  135. package/src/app/component/selection-department/selection-department.component.ts +8 -1
  136. package/src/app/component/send-button/send-button.component.html +5 -13
  137. package/src/app/component/send-button/send-button.component.spec.ts +2 -2
  138. package/src/app/component/star-rating-widget/star-rating-widget.component.html +51 -81
  139. package/src/app/directives/tooltip.directive.spec.ts +8 -4
  140. package/src/app/modals/confirm-close/confirm-close.component.html +20 -8
  141. package/src/app/modals/confirm-close/confirm-close.component.scss +3 -0
  142. package/src/app/modals/confirm-close/confirm-close.component.spec.ts +13 -4
  143. package/src/app/modals/confirm-close/confirm-close.component.ts +8 -1
  144. package/src/app/pipe/html-entites-encode.pipe.spec.ts +35 -2
  145. package/src/app/pipe/marked.pipe.spec.ts +38 -2
  146. package/src/app/pipe/marked.pipe.ts +51 -41
  147. package/src/app/providers/app-config.service.ts +4 -2
  148. package/src/app/providers/brand.service.spec.ts +23 -2
  149. package/src/app/providers/brand.service.ts +1 -1
  150. package/src/app/providers/global-settings.service.spec.ts +1009 -14
  151. package/src/app/providers/global-settings.service.ts +82 -2
  152. package/src/app/providers/json-sources-parser.service.ts +175 -0
  153. package/src/app/providers/translator.service.ts +26 -6
  154. package/src/app/providers/tts-audio-playback-coordinator.service.spec.ts +117 -0
  155. package/src/app/providers/tts-audio-playback-coordinator.service.ts +109 -0
  156. package/src/app/providers/url-preview.service.ts +82 -0
  157. package/src/app/providers/voice/STT&TTS/openai-voice.config.ts +12 -0
  158. package/src/app/providers/voice/STT&TTS/openai-voice.provider.ts +171 -0
  159. package/src/app/providers/voice/STT&TTS/speech-provider.abstract.ts +39 -0
  160. package/src/app/providers/voice/audio.types.ts +40 -0
  161. package/src/app/providers/voice/vad.service.spec.ts +28 -0
  162. package/src/app/providers/voice/vad.service.ts +70 -0
  163. package/src/app/providers/voice/voice-streaming.service.spec.ts +23 -0
  164. package/src/app/providers/voice/voice-streaming.service.ts +702 -0
  165. package/src/app/providers/voice/voice-streaming.types.ts +112 -0
  166. package/src/app/providers/voice/voice.service.spec.ts +227 -0
  167. package/src/app/providers/voice/voice.service.ts +973 -0
  168. package/src/app/sass/_variables.scss +3 -0
  169. package/src/app/sass/animations.scss +19 -1
  170. package/src/app/shims/onnxruntime-web-wasm.ts +4 -0
  171. package/src/app/utils/globals.ts +21 -1
  172. package/src/app/utils/json-sources-utils.ts +27 -0
  173. package/src/app/utils/url-utils.ts +98 -0
  174. package/src/app/utils/utils-resources.ts +1 -1
  175. package/src/assets/i18n/en.json +106 -99
  176. package/src/assets/i18n/es.json +107 -100
  177. package/src/assets/i18n/fr.json +107 -100
  178. package/src/assets/i18n/it.json +107 -98
  179. package/src/assets/onnx/ort-wasm-simd-threaded.mjs +59 -0
  180. package/src/assets/onnx/ort-wasm-simd-threaded.wasm +0 -0
  181. package/src/assets/sounds/keyboard.mp3 +0 -0
  182. package/src/assets/twp/chatbot-panel.html +3 -1
  183. package/src/assets/twp/index-dev.html +18 -0
  184. package/src/assets/twp/tiledesk_widget_files/widget-css-override-example.css +14 -0
  185. package/src/assets/vad/silero_vad_legacy.onnx +0 -0
  186. package/src/assets/vad/vad.worklet.bundle.min.js +1 -0
  187. package/src/chat21-core/models/message.ts +2 -1
  188. package/src/chat21-core/providers/chat-manager.spec.ts +72 -0
  189. package/src/chat21-core/providers/firebase/firebase-conversation-handler.ts +3 -2
  190. package/src/chat21-core/providers/mqtt/mqtt-conversation-handler.ts +12 -0
  191. package/src/chat21-core/providers/scripts/script.service.spec.ts +12 -2
  192. package/src/chat21-core/providers/tiledesk/tiledesk-requests.service.ts +1 -1
  193. package/src/chat21-core/utils/constants.ts +4 -0
  194. package/src/chat21-core/utils/utils-message.ts +45 -6
  195. package/src/chat21-core/utils/utils.ts +5 -2
  196. package/src/widget-config-template.json +4 -1
  197. package/src/widget-config.json +4 -1
  198. package/tests/widget-form-rich.spec.ts +67 -0
  199. package/tests/widget-index-dev-settings.spec.ts +52 -0
  200. package/tests/widget-twp-iframe.spec.ts +39 -0
  201. package/tsconfig.json +5 -0
@@ -1,23 +1,158 @@
1
1
  import { ComponentFixture, TestBed } from '@angular/core/testing';
2
+ import { LoggerInstance } from 'src/chat21-core/providers/logger/loggerInstance';
3
+ import { CustomLogger } from 'src/chat21-core/providers/logger/customLogger';
4
+ import { NGXLogger } from 'ngx-logger';
2
5
 
3
6
  import { AudioComponent } from './audio.component';
4
7
 
5
- describe('AudioTrackComponent', () => {
8
+ describe('AudioComponent', () => {
6
9
  let component: AudioComponent;
7
10
  let fixture: ComponentFixture<AudioComponent>;
11
+ const ngxlogger = jasmine.createSpyObj('NGXLogger', ['log', 'trace', 'debug', 'warn', 'error', 'info']);
12
+ const customLogger = new CustomLogger(ngxlogger);
13
+ const arrayBuf = new ArrayBuffer(64);
14
+
15
+ const fakeBuffer = {
16
+ duration: 90,
17
+ getChannelData: () => new Float32Array(4000),
18
+ } as unknown as AudioBuffer;
8
19
 
9
20
  beforeEach(async () => {
21
+ LoggerInstance.setInstance(customLogger);
22
+ spyOn(window, 'fetch').and.returnValue(
23
+ Promise.resolve({
24
+ arrayBuffer: () => Promise.resolve(arrayBuf),
25
+ } as Response),
26
+ );
27
+ spyOn(AudioContext.prototype, 'decodeAudioData').and.returnValue(Promise.resolve(fakeBuffer));
28
+
10
29
  await TestBed.configureTestingModule({
11
- declarations: [ AudioComponent ]
30
+ declarations: [AudioComponent],
12
31
  })
13
- .compileComponents();
32
+ .overrideComponent(AudioComponent, {
33
+ set: {
34
+ template: `
35
+ <div class="audio-container">
36
+ <div class="audio-track"></div>
37
+ <div class="audio-player-custom">
38
+ <audio #audioElement></audio>
39
+ <canvas #canvasElement width="120" height="32"></canvas>
40
+ </div>
41
+ </div>`,
42
+ },
43
+ })
44
+ .compileComponents();
14
45
 
15
46
  fixture = TestBed.createComponent(AudioComponent);
16
47
  component = fixture.componentInstance;
17
- fixture.detectChanges();
48
+ component.stylesMap = new Map<string, string>([
49
+ ['bubbleSentBackground', 'rgba(10, 20, 30, 1)'],
50
+ ['bubbleSentTextColor', '#112233'],
51
+ ]);
52
+ component.color = '#000000';
18
53
  });
19
54
 
20
- it('should create', () => {
55
+ it('should create', async () => {
56
+ const blob = new Blob([new Uint8Array(arrayBuf.byteLength)], { type: 'audio/wav' });
57
+ component.audioBlob = blob;
58
+ fixture.detectChanges();
59
+ await fixture.whenStable();
60
+ fixture.detectChanges();
21
61
  expect(component).toBeTruthy();
22
62
  });
63
+
64
+ it('formatTime should pad seconds under 10', () => {
65
+ expect(component.formatTime(0)).toBe('0:00');
66
+ expect(component.formatTime(9)).toBe('0:09');
67
+ expect(component.formatTime(70)).toBe('1:10');
68
+ });
69
+
70
+ it('extractFirstColor should parse first rgba from gradient string', () => {
71
+ expect(component.extractFirstColor('linear-gradient(rgba(1, 2, 3, 0.5), red)')).toBe('rgba(1, 2, 3, 0.5)');
72
+ expect(component.extractFirstColor('no-color')).toBeNull();
73
+ });
74
+
75
+ it('drawWaveform should return early when canvas context missing', () => {
76
+ const canvas = document.createElement('canvas');
77
+ spyOn(canvas, 'getContext').and.returnValue(null);
78
+ (component as any).waveformCanvas = { nativeElement: canvas };
79
+ (component as any).audioBuffer = fakeBuffer;
80
+ (component as any).audioDuration = 10;
81
+ (component as any).audioElement = {
82
+ nativeElement: { currentTime: 0, paused: true },
83
+ };
84
+ expect(() => component.drawWaveform(fakeBuffer)).not.toThrow();
85
+ });
86
+
87
+ it('drawWaveform should render bars when context exists', () => {
88
+ const fillRect = jasmine.createSpy('fillRect');
89
+ const clearRect = jasmine.createSpy('clearRect');
90
+ const canvas = document.createElement('canvas');
91
+ canvas.width = 200;
92
+ canvas.height = 40;
93
+ spyOn(canvas, 'getContext').and.returnValue({ fillRect, clearRect } as any);
94
+ (component as any).waveformCanvas = { nativeElement: canvas };
95
+ (component as any).audioElement = {
96
+ nativeElement: { currentTime: 0, paused: true },
97
+ };
98
+ (component as any).audioDuration = 10;
99
+ component.drawWaveform(fakeBuffer);
100
+ expect(clearRect).toHaveBeenCalled();
101
+ expect(fillRect).toHaveBeenCalled();
102
+ });
103
+
104
+ it('ngAfterViewInit with blob should wire object URL and CSS vars', async () => {
105
+ const blob = new Blob([new Uint8Array(128)], { type: 'audio/wav' });
106
+ component.audioBlob = blob;
107
+ spyOn(URL, 'createObjectURL').and.returnValue('blob:mock-audio');
108
+ fixture.detectChanges();
109
+ await fixture.whenStable();
110
+ fixture.detectChanges();
111
+ expect(component.rawAudioUrl).toBe('blob:mock-audio');
112
+ expect(URL.createObjectURL).toHaveBeenCalledWith(blob);
113
+ });
114
+
115
+ it('ngAfterViewInit with metadata.src should fetch and decode', async () => {
116
+ component.audioBlob = null;
117
+ component.metadata = { src: 'blob:from-meta' };
118
+ fixture.detectChanges();
119
+ await fixture.whenStable();
120
+ fixture.detectChanges();
121
+ expect(window.fetch).toHaveBeenCalled();
122
+ expect(component.audioDuration).toBe(90);
123
+ });
124
+
125
+ it('playPauseAudio should toggle play state when buffer ready', () => {
126
+ spyOn(window, 'requestAnimationFrame').and.stub();
127
+ (component as any).audioBuffer = fakeBuffer;
128
+ (component as any).audioDuration = 10;
129
+ const play = jasmine.createSpy('play').and.returnValue(Promise.resolve());
130
+ const pause = jasmine.createSpy('pause');
131
+ const canvas = document.createElement('canvas');
132
+ canvas.width = 120;
133
+ canvas.height = 32;
134
+ spyOn(canvas, 'getContext').and.returnValue({
135
+ fillRect: jasmine.createSpy(),
136
+ clearRect: jasmine.createSpy(),
137
+ } as any);
138
+ (component as any).waveformCanvas = { nativeElement: canvas };
139
+ (component as any).audioElement = {
140
+ nativeElement: { paused: true, currentTime: 0, play, pause, ontimeupdate: null as any, onended: null as any },
141
+ };
142
+ (component as any).audioContext = { resume: jasmine.createSpy().and.returnValue(Promise.resolve()) };
143
+
144
+ component.playPauseAudio();
145
+ expect(play).toHaveBeenCalled();
146
+ expect(component.isPlaying).toBe(true);
147
+
148
+ (component as any).audioElement.nativeElement.paused = false;
149
+ component.playPauseAudio();
150
+ expect(pause).toHaveBeenCalled();
151
+ });
152
+
153
+ it('getAudioDuration should set audioDuration from decoded buffer', async () => {
154
+ component.metadata = { src: 'blob:x' };
155
+ await component.getAudioDuration();
156
+ expect(component.audioDuration).toBe(90);
157
+ });
23
158
  });
@@ -18,6 +18,7 @@ export class AudioComponent implements AfterViewInit {
18
18
  @Input() metadata: any | null = null;
19
19
  @Input() color: string;
20
20
  @Input() stylesMap: Map<string, string>;
21
+ @Input() translationMap: Map<string, string>;
21
22
 
22
23
  audioUrl: SafeUrl | null = null;
23
24
  rawAudioUrl: string | null = null;
@@ -154,15 +155,10 @@ export class AudioComponent implements AfterViewInit {
154
155
  // });
155
156
 
156
157
  const response = await fetch(this.rawAudioUrl!);
157
- this.logger.debug('getAudioDuration: response ---> ', response)
158
158
  const arrayBuffer = await response.arrayBuffer();
159
- this.logger.debug('getAudioDuration: arrayBuffer ---> ', arrayBuffer)
160
159
  const audioContext = new (window.AudioContext || (window as any).webkitAudioContext)();
161
- this.logger.debug('getAudioDuration: audioContext ---> ', audioContext)
162
160
  const audioBuffer = await audioContext.decodeAudioData(arrayBuffer);
163
- this.logger.debug('getAudioDuration: audioBuffer ---> ', audioBuffer)
164
161
  this.audioDuration = audioBuffer.duration;
165
- this.logger.debug('getAudioDuration: audioDuration ---> ', this.audioDuration)
166
162
 
167
163
  }
168
164
 
@@ -0,0 +1,18 @@
1
+ <div class="lyrics-container">
2
+
3
+ <audio
4
+ #audioPlayer
5
+ (timeupdate)="onTimeUpdate()"
6
+ style="display:none">
7
+ </audio>
8
+
9
+ <p class="lyrics message_innerhtml marked" #transcriptBox [style.color]="color">
10
+ <span
11
+ *ngFor="let w of words; let i = index; trackBy: trackByIndex"
12
+ class="word"
13
+ [ngClass]="w.state">
14
+ {{ w.text }}
15
+ </span>
16
+ </p>
17
+
18
+ </div>
@@ -0,0 +1,65 @@
1
+ :host {
2
+ display: block;
3
+ font-size: var(--font-size-bubble-message, 14px);
4
+ }
5
+
6
+ /* Allineato a text.component.scss (.message_innerhtml, p) */
7
+ .message_innerhtml {
8
+ margin: 0;
9
+
10
+ &.marked {
11
+ padding: 12px 16px;
12
+ margin-block-start: 0em !important;
13
+ margin-block-end: 0em !important;
14
+ }
15
+ }
16
+
17
+ .lyrics {
18
+ font-size: inherit;
19
+ margin: 0;
20
+ // line-height: 1.4em;
21
+ font-style: normal;
22
+ letter-spacing: normal;
23
+ font-stretch: normal;
24
+ font-variant: normal;
25
+ font-weight: 300;
26
+ overflow: hidden;
27
+
28
+ display: flex;
29
+ flex-wrap: wrap;
30
+ gap: 6px;
31
+ /* Colore bubble: da [style.color] / @Input() color — ereditato dalle .word */
32
+ }
33
+
34
+ /* base word */
35
+ .word {
36
+ transition:
37
+ transform 0.3s cubic-bezier(0.2, 0.8, 0.2, 1),
38
+ color 0.3s ease,
39
+ opacity 0.3s ease,
40
+ filter 0.3s ease;
41
+
42
+ will-change: transform;
43
+ }
44
+
45
+ /* FUTURE */
46
+ .word.future {
47
+ opacity: 0;
48
+ transform: scale(0.98);
49
+ }
50
+
51
+ /* PAST: stesso colore del testo bubble (@Input color sul <p>) */
52
+ .word.past {
53
+ opacity: 1;
54
+ color: inherit;
55
+ transform: scale(1);
56
+ }
57
+
58
+ /* ACTIVE (solo momentaneo, tipo “karaoke flash”) */
59
+ .word.active {
60
+ opacity: 1;
61
+ color: #00c3ff;
62
+ font-weight: 700;
63
+ transform: scale(1.18);
64
+ text-shadow: 0 0 10px rgba(0, 195, 255, 0.35);
65
+ }
@@ -0,0 +1,103 @@
1
+ import { ComponentFixture, TestBed } from '@angular/core/testing';
2
+ import { CommonModule } from '@angular/common';
3
+
4
+ import { AudioSyncComponent } from './audio-sync.component';
5
+ import { TtsAudioPlaybackCoordinator } from 'src/app/providers/tts-audio-playback-coordinator.service';
6
+ import { VoiceService } from 'src/app/providers/voice/voice.service';
7
+ import { Globals } from 'src/app/utils/globals';
8
+
9
+ describe('AudioSyncComponent', () => {
10
+ let component: AudioSyncComponent;
11
+ let fixture: ComponentFixture<AudioSyncComponent>;
12
+ let voiceService: { proxyTtsStreamUrl: string | null; proxyTtsUrl: string | null };
13
+
14
+ beforeEach(async () => {
15
+ voiceService = {
16
+ proxyTtsStreamUrl: 'https://speech.example.com/api/tts/stream',
17
+ proxyTtsUrl: 'https://speech.example.com/api/tts',
18
+ };
19
+
20
+ await TestBed.configureTestingModule({
21
+ declarations: [AudioSyncComponent],
22
+ imports: [CommonModule],
23
+ providers: [
24
+ {
25
+ provide: TtsAudioPlaybackCoordinator,
26
+ useValue: {
27
+ requestStart: (_ownerId: string, start: () => void) => start(),
28
+ releaseIfCurrent: jasmine.createSpy('releaseIfCurrent'),
29
+ release: jasmine.createSpy('release'),
30
+ stopAllPlayback$: { subscribe: () => ({ unsubscribe: () => undefined }) },
31
+ preemptPlayback$: { subscribe: () => ({ unsubscribe: () => undefined }) },
32
+ },
33
+ },
34
+ { provide: Globals, useValue: { tiledeskToken: 'JWT test-token', jwt: '' } },
35
+ { provide: VoiceService, useValue: voiceService },
36
+ ],
37
+ })
38
+ .compileComponents();
39
+
40
+ fixture = TestBed.createComponent(AudioSyncComponent);
41
+ component = fixture.componentInstance;
42
+ fixture.detectChanges();
43
+ });
44
+
45
+ it('should create', () => {
46
+ expect(component).toBeTruthy();
47
+ });
48
+
49
+ it('starts TTS playback from the proxy streaming endpoint first', () => {
50
+ component.message = {
51
+ uid: 'm1',
52
+ type: 'tts',
53
+ text: 'hello',
54
+ metadata: {},
55
+ isJustRecived: true,
56
+ } as any;
57
+ const audio = document.createElement('audio');
58
+ const startStreaming = spyOn(component as any, 'startStreamingFromEndpoint').and.stub();
59
+
60
+ (component as any).startPlayback(audio);
61
+
62
+ expect(startStreaming).toHaveBeenCalledWith(
63
+ audio,
64
+ 'https://speech.example.com/api/tts/stream',
65
+ 'https://speech.example.com/api/tts',
66
+ undefined,
67
+ );
68
+ });
69
+
70
+ it('requests browser-compatible MP3 for proxy REST TTS by default', () => {
71
+ component.message = {
72
+ uid: 'm1',
73
+ type: 'tts',
74
+ text: 'hello',
75
+ metadata: {},
76
+ } as any;
77
+
78
+ const body = (component as any).buildTtsRequestBody({});
79
+
80
+ expect(body).toEqual({
81
+ text: 'hello',
82
+ streaming: true,
83
+ outputFormat: 'mp3_44100_128',
84
+ });
85
+ });
86
+
87
+ it('does not override an explicit TTS outputFormat from message voice settings', () => {
88
+ component.message = {
89
+ uid: 'm1',
90
+ type: 'tts',
91
+ text: 'hello',
92
+ metadata: {},
93
+ } as any;
94
+
95
+ const body = (component as any).buildTtsRequestBody({ outputFormat: 'pcm_16000' });
96
+
97
+ expect(body).toEqual({
98
+ text: 'hello',
99
+ streaming: true,
100
+ outputFormat: 'pcm_16000',
101
+ });
102
+ });
103
+ });