@magmamath/students-features 1.3.22 → 1.3.23-rc.10

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 (270) hide show
  1. package/dist/commonjs/features/translation/constants.js +11 -0
  2. package/dist/commonjs/features/translation/constants.js.map +1 -0
  3. package/dist/commonjs/features/translation/helpers.js +60 -0
  4. package/dist/commonjs/features/translation/helpers.js.map +1 -0
  5. package/dist/commonjs/features/translation/index.js +105 -0
  6. package/dist/commonjs/features/translation/index.js.map +1 -0
  7. package/dist/commonjs/features/translation/model/TranslationModel.js +122 -0
  8. package/dist/commonjs/features/translation/model/TranslationModel.js.map +1 -0
  9. package/dist/commonjs/features/translation/model/TranslationPreprocessor.js +142 -0
  10. package/dist/commonjs/features/translation/model/TranslationPreprocessor.js.map +1 -0
  11. package/dist/commonjs/features/translation/model/TranslationService.js +112 -0
  12. package/dist/commonjs/features/translation/model/TranslationService.js.map +1 -0
  13. package/dist/commonjs/features/translation/preserve/wordsToPreserve.js +314 -0
  14. package/dist/commonjs/features/translation/preserve/wordsToPreserve.js.map +1 -0
  15. package/dist/commonjs/features/translation/providers/google/GoogleTranslationProvider.js +50 -0
  16. package/dist/commonjs/features/translation/providers/google/GoogleTranslationProvider.js.map +1 -0
  17. package/dist/commonjs/features/translation/providers/google/supportedLanguages.js +230 -0
  18. package/dist/commonjs/features/translation/providers/google/supportedLanguages.js.map +1 -0
  19. package/dist/commonjs/features/translation/providers/google.types.js +2 -0
  20. package/dist/commonjs/features/translation/providers/google.types.js.map +1 -0
  21. package/dist/commonjs/features/translation/providers/translation.interface.js +49 -0
  22. package/dist/commonjs/features/translation/providers/translation.interface.js.map +1 -0
  23. package/dist/commonjs/features/translation/types.js +2 -0
  24. package/dist/commonjs/features/translation/types.js.map +1 -0
  25. package/dist/commonjs/features/voice/index.js +4 -4
  26. package/dist/commonjs/features/voice/index.js.map +1 -1
  27. package/dist/commonjs/features/voice/playing/components/VoiceTranscriptContent.js +44 -0
  28. package/dist/commonjs/features/voice/playing/components/VoiceTranscriptContent.js.map +1 -0
  29. package/dist/commonjs/features/voice/playing/components/VoiceTranscription.js +142 -0
  30. package/dist/commonjs/features/voice/playing/components/VoiceTranscription.js.map +1 -0
  31. package/dist/commonjs/features/voice/playing/components/VoiceTranscriptionCollapsible.js +66 -0
  32. package/dist/commonjs/features/voice/playing/components/VoiceTranscriptionCollapsible.js.map +1 -0
  33. package/dist/commonjs/features/voice/playing/components/VoiceTranscriptionHeaderActions.js +59 -0
  34. package/dist/commonjs/features/voice/playing/components/VoiceTranscriptionHeaderActions.js.map +1 -0
  35. package/dist/commonjs/features/voice/playing/hooks/{useVoiceTranscriptionsDropdown.js → useVoiceTranscription.js} +4 -4
  36. package/dist/commonjs/features/voice/playing/hooks/useVoiceTranscription.js.map +1 -0
  37. package/dist/commonjs/features/voice/playing/hooks/useVoiceTranscriptionAutoTranslate.js +26 -0
  38. package/dist/commonjs/features/voice/playing/hooks/useVoiceTranscriptionAutoTranslate.js.map +1 -0
  39. package/dist/commonjs/features/voice/playing/hooks/useVoiceTranscriptionEffects.js +37 -0
  40. package/dist/commonjs/features/voice/playing/hooks/useVoiceTranscriptionEffects.js.map +1 -0
  41. package/dist/commonjs/features/voice/playing/model/TranscriptionsDownloaderModel.js +18 -4
  42. package/dist/commonjs/features/voice/playing/model/TranscriptionsDownloaderModel.js.map +1 -1
  43. package/dist/commonjs/features/voice/playing/model/VoicePlayer.model.js +6 -2
  44. package/dist/commonjs/features/voice/playing/model/VoicePlayer.model.js.map +1 -1
  45. package/dist/commonjs/features/voice/playing/model/{VoiceTranscriptionsDropdown.model.js → VoiceTranscription.model.js} +4 -4
  46. package/dist/commonjs/features/voice/playing/model/VoiceTranscription.model.js.map +1 -0
  47. package/dist/commonjs/features/voice/playing/model/VoiceTranscriptionTranslation.model.js +62 -0
  48. package/dist/commonjs/features/voice/playing/model/VoiceTranscriptionTranslation.model.js.map +1 -0
  49. package/dist/commonjs/features/voice/types.js +6 -1
  50. package/dist/commonjs/features/voice/types.js.map +1 -1
  51. package/dist/commonjs/index.js +12 -0
  52. package/dist/commonjs/index.js.map +1 -1
  53. package/dist/module/features/translation/constants.js +7 -0
  54. package/dist/module/features/translation/constants.js.map +1 -0
  55. package/dist/module/features/translation/helpers.js +53 -0
  56. package/dist/module/features/translation/helpers.js.map +1 -0
  57. package/dist/module/features/translation/index.js +12 -0
  58. package/dist/module/features/translation/index.js.map +1 -0
  59. package/dist/module/features/translation/model/TranslationModel.js +117 -0
  60. package/dist/module/features/translation/model/TranslationModel.js.map +1 -0
  61. package/dist/module/features/translation/model/TranslationPreprocessor.js +137 -0
  62. package/dist/module/features/translation/model/TranslationPreprocessor.js.map +1 -0
  63. package/dist/module/features/translation/model/TranslationService.js +107 -0
  64. package/dist/module/features/translation/model/TranslationService.js.map +1 -0
  65. package/dist/module/features/translation/preserve/wordsToPreserve.js +310 -0
  66. package/dist/module/features/translation/preserve/wordsToPreserve.js.map +1 -0
  67. package/dist/module/features/translation/providers/google/GoogleTranslationProvider.js +45 -0
  68. package/dist/module/features/translation/providers/google/GoogleTranslationProvider.js.map +1 -0
  69. package/dist/module/features/translation/providers/google/supportedLanguages.js +225 -0
  70. package/dist/module/features/translation/providers/google/supportedLanguages.js.map +1 -0
  71. package/dist/module/features/translation/providers/google.types.js +2 -0
  72. package/dist/module/features/translation/providers/google.types.js.map +1 -0
  73. package/dist/module/features/translation/providers/translation.interface.js +44 -0
  74. package/dist/module/features/translation/providers/translation.interface.js.map +1 -0
  75. package/dist/module/features/translation/types.js +2 -0
  76. package/dist/module/features/translation/types.js.map +1 -0
  77. package/dist/module/features/voice/index.js +1 -1
  78. package/dist/module/features/voice/index.js.map +1 -1
  79. package/dist/module/features/voice/playing/components/VoiceTranscriptContent.js +38 -0
  80. package/dist/module/features/voice/playing/components/VoiceTranscriptContent.js.map +1 -0
  81. package/dist/module/features/voice/playing/components/VoiceTranscription.js +134 -0
  82. package/dist/module/features/voice/playing/components/VoiceTranscription.js.map +1 -0
  83. package/dist/module/features/voice/playing/components/VoiceTranscriptionCollapsible.js +58 -0
  84. package/dist/module/features/voice/playing/components/VoiceTranscriptionCollapsible.js.map +1 -0
  85. package/dist/module/features/voice/playing/components/VoiceTranscriptionHeaderActions.js +51 -0
  86. package/dist/module/features/voice/playing/components/VoiceTranscriptionHeaderActions.js.map +1 -0
  87. package/dist/module/features/voice/playing/hooks/{useVoiceTranscriptionsDropdown.js → useVoiceTranscription.js} +2 -2
  88. package/dist/module/features/voice/playing/hooks/useVoiceTranscription.js.map +1 -0
  89. package/dist/module/features/voice/playing/hooks/useVoiceTranscriptionAutoTranslate.js +21 -0
  90. package/dist/module/features/voice/playing/hooks/useVoiceTranscriptionAutoTranslate.js.map +1 -0
  91. package/dist/module/features/voice/playing/hooks/useVoiceTranscriptionEffects.js +32 -0
  92. package/dist/module/features/voice/playing/hooks/useVoiceTranscriptionEffects.js.map +1 -0
  93. package/dist/module/features/voice/playing/model/TranscriptionsDownloaderModel.js +18 -4
  94. package/dist/module/features/voice/playing/model/TranscriptionsDownloaderModel.js.map +1 -1
  95. package/dist/module/features/voice/playing/model/VoicePlayer.model.js +6 -2
  96. package/dist/module/features/voice/playing/model/VoicePlayer.model.js.map +1 -1
  97. package/dist/module/features/voice/playing/model/{VoiceTranscriptionsDropdown.model.js → VoiceTranscription.model.js} +2 -2
  98. package/dist/module/features/voice/playing/model/VoiceTranscription.model.js.map +1 -0
  99. package/dist/module/features/voice/playing/model/VoiceTranscriptionTranslation.model.js +57 -0
  100. package/dist/module/features/voice/playing/model/VoiceTranscriptionTranslation.model.js.map +1 -0
  101. package/dist/module/features/voice/types.js +5 -0
  102. package/dist/module/features/voice/types.js.map +1 -1
  103. package/dist/module/index.js +1 -0
  104. package/dist/module/index.js.map +1 -1
  105. package/dist/typescript/commonjs/features/translation/constants.d.ts +5 -0
  106. package/dist/typescript/commonjs/features/translation/constants.d.ts.map +1 -0
  107. package/dist/typescript/commonjs/features/translation/helpers.d.ts +9 -0
  108. package/dist/typescript/commonjs/features/translation/helpers.d.ts.map +1 -0
  109. package/dist/typescript/commonjs/features/translation/index.d.ts +12 -0
  110. package/dist/typescript/commonjs/features/translation/index.d.ts.map +1 -0
  111. package/dist/typescript/commonjs/features/translation/model/TranslationModel.d.ts +33 -0
  112. package/dist/typescript/commonjs/features/translation/model/TranslationModel.d.ts.map +1 -0
  113. package/dist/typescript/commonjs/features/translation/model/TranslationPreprocessor.d.ts +34 -0
  114. package/dist/typescript/commonjs/features/translation/model/TranslationPreprocessor.d.ts.map +1 -0
  115. package/dist/typescript/commonjs/features/translation/model/TranslationService.d.ts +40 -0
  116. package/dist/typescript/commonjs/features/translation/model/TranslationService.d.ts.map +1 -0
  117. package/dist/typescript/commonjs/features/translation/preserve/wordsToPreserve.d.ts +3 -0
  118. package/dist/typescript/commonjs/features/translation/preserve/wordsToPreserve.d.ts.map +1 -0
  119. package/dist/typescript/commonjs/features/translation/providers/google/GoogleTranslationProvider.d.ts +17 -0
  120. package/dist/typescript/commonjs/features/translation/providers/google/GoogleTranslationProvider.d.ts.map +1 -0
  121. package/dist/typescript/commonjs/features/translation/providers/google/supportedLanguages.d.ts +209 -0
  122. package/dist/typescript/commonjs/features/translation/providers/google/supportedLanguages.d.ts.map +1 -0
  123. package/dist/typescript/commonjs/features/translation/providers/google.types.d.ts +15 -0
  124. package/dist/typescript/commonjs/features/translation/providers/google.types.d.ts.map +1 -0
  125. package/dist/typescript/commonjs/features/translation/providers/translation.interface.d.ts +30 -0
  126. package/dist/typescript/commonjs/features/translation/providers/translation.interface.d.ts.map +1 -0
  127. package/dist/typescript/commonjs/features/translation/types.d.ts +27 -0
  128. package/dist/typescript/commonjs/features/translation/types.d.ts.map +1 -0
  129. package/dist/typescript/commonjs/features/voice/index.d.ts +1 -1
  130. package/dist/typescript/commonjs/features/voice/index.d.ts.map +1 -1
  131. package/dist/typescript/commonjs/features/voice/playing/components/VoiceTranscriptContent.d.ts +8 -0
  132. package/dist/typescript/commonjs/features/voice/playing/components/VoiceTranscriptContent.d.ts.map +1 -0
  133. package/dist/typescript/commonjs/features/voice/playing/components/VoiceTranscription.d.ts +16 -0
  134. package/dist/typescript/commonjs/features/voice/playing/components/VoiceTranscription.d.ts.map +1 -0
  135. package/dist/typescript/commonjs/features/voice/playing/components/VoiceTranscriptionCollapsible.d.ts +10 -0
  136. package/dist/typescript/commonjs/features/voice/playing/components/VoiceTranscriptionCollapsible.d.ts.map +1 -0
  137. package/dist/typescript/commonjs/features/voice/playing/components/VoiceTranscriptionHeaderActions.d.ts +12 -0
  138. package/dist/typescript/commonjs/features/voice/playing/components/VoiceTranscriptionHeaderActions.d.ts.map +1 -0
  139. package/dist/typescript/{module/features/voice/playing/hooks/useVoiceTranscriptionsDropdown.d.ts → commonjs/features/voice/playing/hooks/useVoiceTranscription.d.ts} +3 -3
  140. package/dist/typescript/commonjs/features/voice/playing/hooks/useVoiceTranscription.d.ts.map +1 -0
  141. package/dist/typescript/commonjs/features/voice/playing/hooks/useVoiceTranscriptionAutoTranslate.d.ts +10 -0
  142. package/dist/typescript/commonjs/features/voice/playing/hooks/useVoiceTranscriptionAutoTranslate.d.ts.map +1 -0
  143. package/dist/typescript/commonjs/features/voice/playing/hooks/useVoiceTranscriptionEffects.d.ts +12 -0
  144. package/dist/typescript/commonjs/features/voice/playing/hooks/useVoiceTranscriptionEffects.d.ts.map +1 -0
  145. package/dist/typescript/commonjs/features/voice/playing/model/TranscriptionsDownloaderModel.d.ts +1 -0
  146. package/dist/typescript/commonjs/features/voice/playing/model/TranscriptionsDownloaderModel.d.ts.map +1 -1
  147. package/dist/typescript/commonjs/features/voice/playing/model/VoicePlayer.model.d.ts +4 -2
  148. package/dist/typescript/commonjs/features/voice/playing/model/VoicePlayer.model.d.ts.map +1 -1
  149. package/dist/typescript/commonjs/features/voice/playing/model/{VoiceTranscriptionsDropdown.model.d.ts → VoiceTranscription.model.d.ts} +2 -2
  150. package/dist/typescript/commonjs/features/voice/playing/model/VoiceTranscription.model.d.ts.map +1 -0
  151. package/dist/typescript/commonjs/features/voice/playing/model/VoiceTranscriptionTranslation.model.d.ts +25 -0
  152. package/dist/typescript/commonjs/features/voice/playing/model/VoiceTranscriptionTranslation.model.d.ts.map +1 -0
  153. package/dist/typescript/commonjs/features/voice/types.d.ts +9 -1
  154. package/dist/typescript/commonjs/features/voice/types.d.ts.map +1 -1
  155. package/dist/typescript/commonjs/index.d.ts +1 -0
  156. package/dist/typescript/commonjs/index.d.ts.map +1 -1
  157. package/dist/typescript/module/features/translation/constants.d.ts +5 -0
  158. package/dist/typescript/module/features/translation/constants.d.ts.map +1 -0
  159. package/dist/typescript/module/features/translation/helpers.d.ts +9 -0
  160. package/dist/typescript/module/features/translation/helpers.d.ts.map +1 -0
  161. package/dist/typescript/module/features/translation/index.d.ts +12 -0
  162. package/dist/typescript/module/features/translation/index.d.ts.map +1 -0
  163. package/dist/typescript/module/features/translation/model/TranslationModel.d.ts +33 -0
  164. package/dist/typescript/module/features/translation/model/TranslationModel.d.ts.map +1 -0
  165. package/dist/typescript/module/features/translation/model/TranslationPreprocessor.d.ts +34 -0
  166. package/dist/typescript/module/features/translation/model/TranslationPreprocessor.d.ts.map +1 -0
  167. package/dist/typescript/module/features/translation/model/TranslationService.d.ts +40 -0
  168. package/dist/typescript/module/features/translation/model/TranslationService.d.ts.map +1 -0
  169. package/dist/typescript/module/features/translation/preserve/wordsToPreserve.d.ts +3 -0
  170. package/dist/typescript/module/features/translation/preserve/wordsToPreserve.d.ts.map +1 -0
  171. package/dist/typescript/module/features/translation/providers/google/GoogleTranslationProvider.d.ts +17 -0
  172. package/dist/typescript/module/features/translation/providers/google/GoogleTranslationProvider.d.ts.map +1 -0
  173. package/dist/typescript/module/features/translation/providers/google/supportedLanguages.d.ts +209 -0
  174. package/dist/typescript/module/features/translation/providers/google/supportedLanguages.d.ts.map +1 -0
  175. package/dist/typescript/module/features/translation/providers/google.types.d.ts +15 -0
  176. package/dist/typescript/module/features/translation/providers/google.types.d.ts.map +1 -0
  177. package/dist/typescript/module/features/translation/providers/translation.interface.d.ts +30 -0
  178. package/dist/typescript/module/features/translation/providers/translation.interface.d.ts.map +1 -0
  179. package/dist/typescript/module/features/translation/types.d.ts +27 -0
  180. package/dist/typescript/module/features/translation/types.d.ts.map +1 -0
  181. package/dist/typescript/module/features/voice/index.d.ts +1 -1
  182. package/dist/typescript/module/features/voice/index.d.ts.map +1 -1
  183. package/dist/typescript/module/features/voice/playing/components/VoiceTranscriptContent.d.ts +8 -0
  184. package/dist/typescript/module/features/voice/playing/components/VoiceTranscriptContent.d.ts.map +1 -0
  185. package/dist/typescript/module/features/voice/playing/components/VoiceTranscription.d.ts +16 -0
  186. package/dist/typescript/module/features/voice/playing/components/VoiceTranscription.d.ts.map +1 -0
  187. package/dist/typescript/module/features/voice/playing/components/VoiceTranscriptionCollapsible.d.ts +10 -0
  188. package/dist/typescript/module/features/voice/playing/components/VoiceTranscriptionCollapsible.d.ts.map +1 -0
  189. package/dist/typescript/module/features/voice/playing/components/VoiceTranscriptionHeaderActions.d.ts +12 -0
  190. package/dist/typescript/module/features/voice/playing/components/VoiceTranscriptionHeaderActions.d.ts.map +1 -0
  191. package/dist/typescript/{commonjs/features/voice/playing/hooks/useVoiceTranscriptionsDropdown.d.ts → module/features/voice/playing/hooks/useVoiceTranscription.d.ts} +3 -3
  192. package/dist/typescript/module/features/voice/playing/hooks/useVoiceTranscription.d.ts.map +1 -0
  193. package/dist/typescript/module/features/voice/playing/hooks/useVoiceTranscriptionAutoTranslate.d.ts +10 -0
  194. package/dist/typescript/module/features/voice/playing/hooks/useVoiceTranscriptionAutoTranslate.d.ts.map +1 -0
  195. package/dist/typescript/module/features/voice/playing/hooks/useVoiceTranscriptionEffects.d.ts +12 -0
  196. package/dist/typescript/module/features/voice/playing/hooks/useVoiceTranscriptionEffects.d.ts.map +1 -0
  197. package/dist/typescript/module/features/voice/playing/model/TranscriptionsDownloaderModel.d.ts +1 -0
  198. package/dist/typescript/module/features/voice/playing/model/TranscriptionsDownloaderModel.d.ts.map +1 -1
  199. package/dist/typescript/module/features/voice/playing/model/VoicePlayer.model.d.ts +4 -2
  200. package/dist/typescript/module/features/voice/playing/model/VoicePlayer.model.d.ts.map +1 -1
  201. package/dist/typescript/module/features/voice/playing/model/{VoiceTranscriptionsDropdown.model.d.ts → VoiceTranscription.model.d.ts} +2 -2
  202. package/dist/typescript/module/features/voice/playing/model/VoiceTranscription.model.d.ts.map +1 -0
  203. package/dist/typescript/module/features/voice/playing/model/VoiceTranscriptionTranslation.model.d.ts +25 -0
  204. package/dist/typescript/module/features/voice/playing/model/VoiceTranscriptionTranslation.model.d.ts.map +1 -0
  205. package/dist/typescript/module/features/voice/types.d.ts +9 -1
  206. package/dist/typescript/module/features/voice/types.d.ts.map +1 -1
  207. package/dist/typescript/module/index.d.ts +1 -0
  208. package/dist/typescript/module/index.d.ts.map +1 -1
  209. package/package.json +1 -1
  210. package/src/features/translation/constants.ts +4 -0
  211. package/src/features/translation/helpers.ts +63 -0
  212. package/src/features/translation/index.ts +30 -0
  213. package/src/features/translation/model/TranslationModel.ts +174 -0
  214. package/src/features/translation/model/TranslationPreprocessor.ts +171 -0
  215. package/src/features/translation/model/TranslationService.ts +148 -0
  216. package/src/features/translation/preserve/wordsToPreserve.ts +87 -0
  217. package/src/features/translation/providers/google/GoogleTranslationProvider.ts +50 -0
  218. package/src/features/translation/providers/google/supportedLanguages.ts +229 -0
  219. package/src/features/translation/providers/google.types.ts +16 -0
  220. package/src/features/translation/providers/translation.interface.ts +63 -0
  221. package/src/features/translation/types.ts +30 -0
  222. package/src/features/voice/index.ts +1 -1
  223. package/src/features/voice/playing/components/VoiceTranscriptContent.tsx +37 -0
  224. package/src/features/voice/playing/components/VoiceTranscription.tsx +175 -0
  225. package/src/features/voice/playing/components/VoiceTranscriptionCollapsible.tsx +59 -0
  226. package/src/features/voice/playing/components/VoiceTranscriptionHeaderActions.tsx +62 -0
  227. package/src/features/voice/playing/hooks/{useVoiceTranscriptionsDropdown.ts → useVoiceTranscription.ts} +2 -2
  228. package/src/features/voice/playing/hooks/useVoiceTranscriptionAutoTranslate.ts +32 -0
  229. package/src/features/voice/playing/hooks/useVoiceTranscriptionEffects.ts +44 -0
  230. package/src/features/voice/playing/model/TranscriptionsDownloaderModel.ts +12 -5
  231. package/src/features/voice/playing/model/VoicePlayer.model.ts +7 -2
  232. package/src/features/voice/playing/model/{VoiceTranscriptionsDropdown.model.ts → VoiceTranscription.model.ts} +2 -2
  233. package/src/features/voice/playing/model/VoiceTranscriptionTranslation.model.ts +75 -0
  234. package/src/features/voice/types.ts +15 -0
  235. package/src/index.ts +1 -0
  236. package/dist/commonjs/features/voice/playing/components/VoiceTranscriptionsDropdown.js +0 -245
  237. package/dist/commonjs/features/voice/playing/components/VoiceTranscriptionsDropdown.js.map +0 -1
  238. package/dist/commonjs/features/voice/playing/components/VoiceTranscriptionsDropdownItem.js +0 -109
  239. package/dist/commonjs/features/voice/playing/components/VoiceTranscriptionsDropdownItem.js.map +0 -1
  240. package/dist/commonjs/features/voice/playing/hooks/useVoiceTranscriptionsDropdown.js.map +0 -1
  241. package/dist/commonjs/features/voice/playing/hooks/useVoiceTranscriptionsDropdownItemAnimation.js +0 -34
  242. package/dist/commonjs/features/voice/playing/hooks/useVoiceTranscriptionsDropdownItemAnimation.js.map +0 -1
  243. package/dist/commonjs/features/voice/playing/model/VoiceTranscriptionsDropdown.model.js.map +0 -1
  244. package/dist/module/features/voice/playing/components/VoiceTranscriptionsDropdown.js +0 -238
  245. package/dist/module/features/voice/playing/components/VoiceTranscriptionsDropdown.js.map +0 -1
  246. package/dist/module/features/voice/playing/components/VoiceTranscriptionsDropdownItem.js +0 -103
  247. package/dist/module/features/voice/playing/components/VoiceTranscriptionsDropdownItem.js.map +0 -1
  248. package/dist/module/features/voice/playing/hooks/useVoiceTranscriptionsDropdown.js.map +0 -1
  249. package/dist/module/features/voice/playing/hooks/useVoiceTranscriptionsDropdownItemAnimation.js +0 -29
  250. package/dist/module/features/voice/playing/hooks/useVoiceTranscriptionsDropdownItemAnimation.js.map +0 -1
  251. package/dist/module/features/voice/playing/model/VoiceTranscriptionsDropdown.model.js.map +0 -1
  252. package/dist/typescript/commonjs/features/voice/playing/components/VoiceTranscriptionsDropdown.d.ts +0 -16
  253. package/dist/typescript/commonjs/features/voice/playing/components/VoiceTranscriptionsDropdown.d.ts.map +0 -1
  254. package/dist/typescript/commonjs/features/voice/playing/components/VoiceTranscriptionsDropdownItem.d.ts +0 -12
  255. package/dist/typescript/commonjs/features/voice/playing/components/VoiceTranscriptionsDropdownItem.d.ts.map +0 -1
  256. package/dist/typescript/commonjs/features/voice/playing/hooks/useVoiceTranscriptionsDropdown.d.ts.map +0 -1
  257. package/dist/typescript/commonjs/features/voice/playing/hooks/useVoiceTranscriptionsDropdownItemAnimation.d.ts +0 -11
  258. package/dist/typescript/commonjs/features/voice/playing/hooks/useVoiceTranscriptionsDropdownItemAnimation.d.ts.map +0 -1
  259. package/dist/typescript/commonjs/features/voice/playing/model/VoiceTranscriptionsDropdown.model.d.ts.map +0 -1
  260. package/dist/typescript/module/features/voice/playing/components/VoiceTranscriptionsDropdown.d.ts +0 -16
  261. package/dist/typescript/module/features/voice/playing/components/VoiceTranscriptionsDropdown.d.ts.map +0 -1
  262. package/dist/typescript/module/features/voice/playing/components/VoiceTranscriptionsDropdownItem.d.ts +0 -12
  263. package/dist/typescript/module/features/voice/playing/components/VoiceTranscriptionsDropdownItem.d.ts.map +0 -1
  264. package/dist/typescript/module/features/voice/playing/hooks/useVoiceTranscriptionsDropdown.d.ts.map +0 -1
  265. package/dist/typescript/module/features/voice/playing/hooks/useVoiceTranscriptionsDropdownItemAnimation.d.ts +0 -11
  266. package/dist/typescript/module/features/voice/playing/hooks/useVoiceTranscriptionsDropdownItemAnimation.d.ts.map +0 -1
  267. package/dist/typescript/module/features/voice/playing/model/VoiceTranscriptionsDropdown.model.d.ts.map +0 -1
  268. package/src/features/voice/playing/components/VoiceTranscriptionsDropdown.tsx +0 -296
  269. package/src/features/voice/playing/components/VoiceTranscriptionsDropdownItem.tsx +0 -128
  270. package/src/features/voice/playing/hooks/useVoiceTranscriptionsDropdownItemAnimation.ts +0 -40
@@ -0,0 +1,175 @@
1
+ import { Typography, COLORS } from '@magmamath/react-native-ui'
2
+ import { useUnit } from 'effector-react'
3
+ import React, { useCallback, useEffect, useMemo } from 'react'
4
+ import { useTranslation } from 'react-i18next'
5
+ import { StyleProp, StyleSheet, View, ViewStyle } from 'react-native'
6
+ import Animated from 'react-native-reanimated'
7
+ import { NO_AUDIO_BE_MESSAGE } from '../../constants'
8
+ import { getActiveAttempt } from '../../helpers'
9
+ import { AnswerAudio, VoiceTranscriptionVariant } from '../../types'
10
+ import { resolveGoogleLanguageCode } from '../../../translation/providers/google/supportedLanguages'
11
+ import { useText } from '../../../../i18n/i18n'
12
+ import { useVoiceTranscriptionEffects } from '../hooks/useVoiceTranscriptionEffects'
13
+ import { useVoiceTranscriptionAutoTranslate } from '../hooks/useVoiceTranscriptionAutoTranslate'
14
+ import { VoicePlayerModel } from '../model'
15
+ import { VoiceTranscriptContent } from './VoiceTranscriptContent'
16
+ import { VoiceTranscriptionCollapsible } from './VoiceTranscriptionCollapsible'
17
+ import { VoiceTranscriptionHeaderActions } from './VoiceTranscriptionHeaderActions'
18
+
19
+ type VoiceTranscriptionProps = {
20
+ style?: StyleProp<ViewStyle>
21
+ model: VoicePlayerModel
22
+ answers: AnswerAudio[]
23
+ attemptOffset: number
24
+ attemptsCount: number
25
+ problemId: string
26
+ variant?: VoiceTranscriptionVariant
27
+ }
28
+
29
+ export const VoiceTranscription = ({
30
+ style,
31
+ model,
32
+ answers,
33
+ attemptOffset,
34
+ attemptsCount,
35
+ problemId,
36
+ variant = VoiceTranscriptionVariant.SMALL,
37
+ }: VoiceTranscriptionProps) => {
38
+ const t = useText()
39
+ const { i18n } = useTranslation()
40
+
41
+ const [playerState, isLoadingTranscripts, isTranslationActive, translations, isTranslating] =
42
+ useUnit([
43
+ model.$playerState,
44
+ model.loader.loadAllTranscripts.pending,
45
+ model.translation.$isActive,
46
+ model.translation.$translations,
47
+ model.translation.translate.pending,
48
+ ])
49
+
50
+ const activeAttempt = getActiveAttempt(attemptOffset, attemptsCount)
51
+ const isLargeVariant = variant === VoiceTranscriptionVariant.LARGE
52
+
53
+ const answersKey = useMemo(
54
+ () => answers.map((a) => `${a._id}:${a.audioFileId ?? ''}`).join(','),
55
+ [answers],
56
+ )
57
+
58
+ useVoiceTranscriptionEffects({ model, answers, answersKey, problemId, activeAttempt })
59
+
60
+ const hasActiveAudio =
61
+ activeAttempt !== null && answers?.[activeAttempt - 1]?.audioFileId !== undefined
62
+
63
+ const activeTranscript = activeAttempt !== null ? model.loader.getTranscript(activeAttempt) : null
64
+ const hasTranscriptText = !!activeTranscript && activeTranscript !== NO_AUDIO_BE_MESSAGE
65
+ const isActiveTranscriptLoading = isLoadingTranscripts && hasActiveAudio && !activeTranscript
66
+
67
+ const transcriptLanguage =
68
+ activeAttempt !== null ? model.loader.getTranscriptLanguage(activeAttempt) : undefined
69
+ const isSourceSameAsTarget =
70
+ !!transcriptLanguage &&
71
+ resolveGoogleLanguageCode(transcriptLanguage) === resolveGoogleLanguageCode(i18n.language)
72
+
73
+ const canTranslate = hasTranscriptText && !isSourceSameAsTarget
74
+
75
+ const cachedTranslation = activeAttempt !== null ? translations[activeAttempt] : undefined
76
+ const showTranslation = isTranslationActive && canTranslate
77
+ const isTranslationLoading = showTranslation && !cachedTranslation && isTranslating
78
+
79
+ const displayText = showTranslation
80
+ ? (cachedTranslation ?? activeTranscript!)
81
+ : hasTranscriptText
82
+ ? activeTranscript!
83
+ : t('voice.transcriptNotAvailable')
84
+
85
+ useVoiceTranscriptionAutoTranslate({
86
+ translationModel: model.translation,
87
+ canTranslate,
88
+ activeAttempt,
89
+ problemId,
90
+ })
91
+
92
+ useEffect(() => {
93
+ if (showTranslation && activeAttempt !== null && !cachedTranslation && !isTranslating) {
94
+ model.translation.translate({
95
+ attemptNumber: activeAttempt,
96
+ targetLanguage: i18n.language,
97
+ })
98
+ }
99
+ }, [showTranslation, activeAttempt, cachedTranslation, isTranslating, i18n.language, model])
100
+
101
+ const handlePlayPress = useCallback(() => {
102
+ if (activeAttempt) {
103
+ model.translation.setActive(false)
104
+ model.togglePlayPause(activeAttempt)
105
+ }
106
+ }, [model, activeAttempt])
107
+
108
+ const handleTranslationToggle = useCallback(() => {
109
+ model.translation.toggle()
110
+ }, [model])
111
+
112
+ return (
113
+ <Animated.View style={[styles.container, isLargeVariant && styles.largeContainer, style]}>
114
+ <View style={styles.header}>
115
+ <Typography style={styles.title} variant="h7">
116
+ {t('voice.transcriptions')}
117
+ </Typography>
118
+ {hasActiveAudio && (
119
+ <VoiceTranscriptionHeaderActions
120
+ playerState={playerState}
121
+ isTranslationActive={isTranslationActive}
122
+ canTranslate={canTranslate}
123
+ onPlayPress={handlePlayPress}
124
+ onTranslationPress={handleTranslationToggle}
125
+ />
126
+ )}
127
+ </View>
128
+
129
+ {isLargeVariant ? (
130
+ <VoiceTranscriptContent
131
+ text={displayText}
132
+ isLoading={isActiveTranscriptLoading || isTranslationLoading}
133
+ />
134
+ ) : (
135
+ <VoiceTranscriptionCollapsible
136
+ text={displayText}
137
+ isLoading={isActiveTranscriptLoading || isTranslationLoading}
138
+ dropdown={model.dropdown}
139
+ />
140
+ )}
141
+ </Animated.View>
142
+ )
143
+ }
144
+
145
+ const styles = StyleSheet.create({
146
+ container: {
147
+ position: 'absolute',
148
+ top: 56,
149
+ left: 8,
150
+ width: 222,
151
+ maxHeight: 405,
152
+ minHeight: 51,
153
+ padding: 4,
154
+ boxShadow: '0px 1px 3px 0px rgba(51, 51, 51, 0.25)',
155
+ borderRadius: 12,
156
+ backgroundColor: COLORS.NEUTRAL_1,
157
+ overflow: 'hidden',
158
+ },
159
+ largeContainer: {
160
+ width: '98%',
161
+ height: '100%',
162
+ },
163
+ header: {
164
+ flexDirection: 'row',
165
+ justifyContent: 'space-between',
166
+ alignItems: 'center',
167
+ padding: 4,
168
+ marginBottom: 4,
169
+ height: 32,
170
+ },
171
+ title: {
172
+ color: COLORS.NEUTRAL_9,
173
+ marginLeft: 4,
174
+ },
175
+ })
@@ -0,0 +1,59 @@
1
+ import { CaretDownIcon } from '@magmamath/react-native-ui'
2
+ import React, { useCallback } from 'react'
3
+ import { StyleSheet, TouchableOpacity, View } from 'react-native'
4
+ import Animated from 'react-native-reanimated'
5
+ import { useVoiceTranscriptionDropdown } from '../hooks/useVoiceTranscription'
6
+ import { VoiceTranscriptionModel } from '../model/VoiceTranscription.model'
7
+ import { VoiceTranscriptContent } from './VoiceTranscriptContent'
8
+
9
+ const AnimatedTouchableOpacity = Animated.createAnimatedComponent(TouchableOpacity)
10
+
11
+ type VoiceTranscriptionCollapsibleProps = {
12
+ text: string
13
+ isLoading: boolean
14
+ dropdown: VoiceTranscriptionModel
15
+ }
16
+
17
+ export const VoiceTranscriptionCollapsible = ({
18
+ text,
19
+ isLoading,
20
+ dropdown,
21
+ }: VoiceTranscriptionCollapsibleProps) => {
22
+ const { listAnimatedStyle, iconAnimatedStyle, onListLayout } =
23
+ useVoiceTranscriptionDropdown(dropdown)
24
+
25
+ const handleToggle = useCallback(() => {
26
+ dropdown.toggleExpand()
27
+ }, [dropdown])
28
+
29
+ return (
30
+ <>
31
+ <Animated.View style={[listAnimatedStyle, styles.collapsibleContent]}>
32
+ <View onLayout={onListLayout} style={styles.transcriptContainer}>
33
+ <VoiceTranscriptContent text={text} isLoading={isLoading} />
34
+ </View>
35
+ </Animated.View>
36
+ <AnimatedTouchableOpacity
37
+ style={[styles.expandButton, iconAnimatedStyle]}
38
+ onPress={handleToggle}
39
+ >
40
+ <CaretDownIcon size={22} />
41
+ </AnimatedTouchableOpacity>
42
+ </>
43
+ )
44
+ }
45
+
46
+ const styles = StyleSheet.create({
47
+ collapsibleContent: {
48
+ overflow: 'hidden',
49
+ },
50
+ transcriptContainer: {
51
+ position: 'absolute',
52
+ width: '100%',
53
+ paddingHorizontal: 4,
54
+ },
55
+ expandButton: {
56
+ justifyContent: 'center',
57
+ alignItems: 'center',
58
+ },
59
+ })
@@ -0,0 +1,62 @@
1
+ import { Button, COLORS, GlobeIcon, SPACING } from '@magmamath/react-native-ui'
2
+ import React from 'react'
3
+ import { StyleSheet } from 'react-native'
4
+ import Animated, { FadeIn, FadeOut } from 'react-native-reanimated'
5
+ import { ColorScheme } from '../../../chatbot/types/style.types'
6
+ import { PlayButton } from '../../../../shared/components/PlayButton'
7
+ import { PlayerState } from '../model'
8
+ import { getAudioStatus } from '../../helpers'
9
+
10
+ type VoiceTranscriptionsHeaderActionsProps = {
11
+ playerState: PlayerState
12
+ isTranslationActive: boolean
13
+ canTranslate: boolean
14
+ onPlayPress: () => void
15
+ onTranslationPress: () => void
16
+ }
17
+
18
+ export const VoiceTranscriptionHeaderActions = ({
19
+ playerState,
20
+ isTranslationActive,
21
+ canTranslate,
22
+ onPlayPress,
23
+ onTranslationPress,
24
+ }: VoiceTranscriptionsHeaderActionsProps) => {
25
+ const playButtonState = {
26
+ isActive: playerState !== PlayerState.IDLE,
27
+ isLoading: playerState === PlayerState.LOADING,
28
+ status: getAudioStatus(playerState),
29
+ }
30
+
31
+ return (
32
+ <Animated.View
33
+ entering={FadeIn.duration(120)}
34
+ exiting={FadeOut.duration(120)}
35
+ style={styles.container}
36
+ >
37
+ <PlayButton
38
+ state={playButtonState}
39
+ onPress={onPlayPress}
40
+ activityIndicatorColor={COLORS.NEUTRAL_1}
41
+ />
42
+ {canTranslate && (
43
+ <Button
44
+ variant="secondary"
45
+ size="small"
46
+ colorScheme={ColorScheme.Blue}
47
+ isActive={isTranslationActive}
48
+ onPress={onTranslationPress}
49
+ icon={<GlobeIcon color={isTranslationActive ? COLORS.NEUTRAL_1 : COLORS.NEUTRAL_9} />}
50
+ />
51
+ )}
52
+ </Animated.View>
53
+ )
54
+ }
55
+
56
+ const styles = StyleSheet.create({
57
+ container: {
58
+ flexDirection: 'row',
59
+ alignItems: 'center',
60
+ gap: SPACING[200],
61
+ },
62
+ })
@@ -1,11 +1,11 @@
1
1
  import { useEffect } from 'react'
2
2
  import { useUnit } from 'effector-react'
3
3
  import { useAnimatedStyle, useSharedValue, withTiming, interpolate } from 'react-native-reanimated'
4
- import { VoiceTranscriptionsDropdownModel } from '../model/VoiceTranscriptionsDropdown.model'
4
+ import { VoiceTranscriptionModel } from '../model/VoiceTranscription.model'
5
5
  import { DROPDOWN_MAX_CONTENT_HEIGHT } from '../../constants'
6
6
  import { LayoutChangeEvent } from 'react-native'
7
7
 
8
- export const useVoiceTranscriptionsDropdown = (model: VoiceTranscriptionsDropdownModel) => {
8
+ export const useVoiceTranscriptionDropdown = (model: VoiceTranscriptionModel) => {
9
9
  const isExpanded = useUnit(model.$isExpanded)
10
10
 
11
11
  const contentHeight = useSharedValue(0)
@@ -0,0 +1,32 @@
1
+ import { useEffect, useRef } from 'react'
2
+ import { VoiceTranscriptionTranslationModel } from '../model/VoiceTranscriptionTranslation.model'
3
+
4
+ type Params = {
5
+ translationModel: VoiceTranscriptionTranslationModel
6
+ canTranslate: boolean
7
+ activeAttempt: number | null
8
+ problemId: string
9
+ }
10
+ export const useVoiceTranscriptionAutoTranslate = ({
11
+ translationModel,
12
+ canTranslate,
13
+ activeAttempt,
14
+ problemId,
15
+ }: Params) => {
16
+ const autoActivatedAttempts = useRef(new Set<number>())
17
+
18
+ useEffect(() => {
19
+ autoActivatedAttempts.current.clear()
20
+ }, [problemId])
21
+
22
+ useEffect(() => {
23
+ if (
24
+ canTranslate &&
25
+ activeAttempt !== null &&
26
+ !autoActivatedAttempts.current.has(activeAttempt)
27
+ ) {
28
+ autoActivatedAttempts.current.add(activeAttempt)
29
+ translationModel.setActive(true)
30
+ }
31
+ }, [canTranslate, activeAttempt, translationModel])
32
+ }
@@ -0,0 +1,44 @@
1
+ import { useEffect, useRef } from 'react'
2
+ import { AnswerAudio } from '../../types'
3
+ import { VoicePlayerModel } from '../model'
4
+
5
+ type Params = {
6
+ model: VoicePlayerModel
7
+ answers: AnswerAudio[]
8
+ answersKey: string
9
+ problemId: string
10
+ activeAttempt: number | null
11
+ }
12
+
13
+ export const useVoiceTranscriptionEffects = ({
14
+ model,
15
+ answers,
16
+ answersKey,
17
+ problemId,
18
+ activeAttempt,
19
+ }: Params) => {
20
+ const answersRef = useRef(answers)
21
+ answersRef.current = answers
22
+
23
+ useEffect(() => {
24
+ model.reinitializePlayer()
25
+ return () => model.cleanup()
26
+ }, [model])
27
+
28
+ useEffect(() => {
29
+ const lastAnswerHasNoDrawing = !answers[answers.length - 1]?.drawing
30
+ model.dropdown.setExpanded(answers.length > 0 && lastAnswerHasNoDrawing)
31
+ model.resetPlayer()
32
+ }, [problemId])
33
+
34
+ useEffect(() => {
35
+ if (answersRef.current.some((answer) => answer.audioFileId)) {
36
+ model.initializeWithAudios(answersRef.current)
37
+ model.loader.loadAllTranscripts()
38
+ }
39
+ }, [model, answersKey])
40
+
41
+ useEffect(() => {
42
+ model.stopAudio()
43
+ }, [activeAttempt])
44
+ }
@@ -21,23 +21,25 @@ export class TranscriptionsDownloaderModel {
21
21
  this.api = api
22
22
  }
23
23
 
24
- private async fetchTranscriptWithRetry(audioFileId: string): Promise<string> {
24
+ private async fetchTranscriptWithRetry(
25
+ audioFileId: string,
26
+ ): Promise<{ text: string; language?: string }> {
25
27
  for (let attempt = 0; attempt < TRANSCRIPT_MAX_RETRIES; attempt++) {
26
28
  const response = await this.api.getAudioFileTranscript(audioFileId)
27
29
 
28
30
  if (response.status === 'completed') {
29
- return response.text
31
+ return { text: response.text, language: response.language }
30
32
  }
31
33
 
32
34
  if (response.status === 'failed') {
33
- return NO_AUDIO_BE_MESSAGE
35
+ return { text: NO_AUDIO_BE_MESSAGE }
34
36
  }
35
37
 
36
38
  if (attempt < TRANSCRIPT_MAX_RETRIES - 1) {
37
39
  await new Promise((resolve) => setTimeout(resolve, TRANSCRIPT_RETRY_INTERVAL_MS))
38
40
  }
39
41
  }
40
- return NO_AUDIO_BE_MESSAGE
42
+ return { text: NO_AUDIO_BE_MESSAGE }
41
43
  }
42
44
 
43
45
  public readonly loadAllTranscripts = createEffect(async () => {
@@ -51,10 +53,11 @@ export class TranscriptionsDownloaderModel {
51
53
  this.collection.update(item.attemptNumber, { transcriptLoading: true })
52
54
 
53
55
  try {
54
- const text = await this.fetchTranscriptWithRetry(item.audioFileId)
56
+ const { text, language } = await this.fetchTranscriptWithRetry(item.audioFileId)
55
57
 
56
58
  this.collection.update(item.attemptNumber, {
57
59
  transcript: text,
60
+ transcriptLanguage: language,
58
61
  transcriptLoading: false,
59
62
  transcriptError: undefined,
60
63
  })
@@ -74,6 +77,10 @@ export class TranscriptionsDownloaderModel {
74
77
  return this.collection.get(attemptNumber)?.transcript
75
78
  }
76
79
 
80
+ public getTranscriptLanguage(attemptNumber: number): string | undefined {
81
+ return this.collection.get(attemptNumber)?.transcriptLanguage
82
+ }
83
+
77
84
  public isTranscriptLoading(attemptNumber: number): boolean {
78
85
  return this.collection.get(attemptNumber)?.transcriptLoading || false
79
86
  }
@@ -1,7 +1,8 @@
1
1
  import { attach, createEffect, createEvent, restore } from 'effector'
2
2
  import { VoiceTranscriptionsCollection } from './VoiceTranscriptionsCollection'
3
3
  import { VoiceFileDownloaderModel } from './VoiceFileDownloader.model'
4
- import { VoiceTranscriptionsDropdownModel } from './VoiceTranscriptionsDropdown.model'
4
+ import { VoiceTranscriptionModel } from './VoiceTranscription.model'
5
+ import { VoiceTranscriptionTranslationModel } from './VoiceTranscriptionTranslation.model'
5
6
  import { AnswerAudio, VoicePlayerApi, VoiceTranscriptionItem } from '../../types'
6
7
  import { PlayerModel, PlayerState } from './Player.model'
7
8
  import { TranscriptionsDownloaderModel } from './TranscriptionsDownloaderModel'
@@ -18,7 +19,8 @@ type TogglePlayPauseParams = {
18
19
  export class VoicePlayerModel {
19
20
  public readonly collection = new VoiceTranscriptionsCollection()
20
21
  public readonly downloader = new VoiceFileDownloaderModel()
21
- public readonly dropdown = new VoiceTranscriptionsDropdownModel()
22
+ public readonly dropdown = new VoiceTranscriptionModel()
23
+ public readonly translation: VoiceTranscriptionTranslationModel
22
24
  public readonly playerModel = new PlayerModel()
23
25
  public readonly loader: TranscriptionsDownloaderModel
24
26
  public readonly api: VoicePlayerApi
@@ -48,11 +50,13 @@ export class VoicePlayerModel {
48
50
  this.currentPlayingAttempt = null
49
51
  this.setCurrentAttempt(null)
50
52
  this.collection.clear()
53
+ this.translation.clearCache()
51
54
  }
52
55
 
53
56
  constructor(params: VoiceTranscriptionsPlayerModelParams) {
54
57
  this.api = params.api
55
58
  this.loader = new TranscriptionsDownloaderModel(this.collection, params.api)
59
+ this.translation = new VoiceTranscriptionTranslationModel(this.collection, params.api)
56
60
  this.downloader.setApi(params.api)
57
61
 
58
62
  this.playerModel.playbackFinished.watch(() => {
@@ -238,6 +242,7 @@ export class VoicePlayerModel {
238
242
  this.reset()
239
243
  this.loader.reset()
240
244
  this.dropdown.reset()
245
+ this.translation.reset()
241
246
  this.playerModel.release()
242
247
  }
243
248
 
@@ -1,6 +1,6 @@
1
- import { createEvent, createStore, restore } from 'effector'
1
+ import { createEvent, restore } from 'effector'
2
2
 
3
- export class VoiceTranscriptionsDropdownModel {
3
+ export class VoiceTranscriptionModel {
4
4
  public readonly toggleExpand = createEvent()
5
5
  public readonly setExpanded = createEvent<boolean>()
6
6
  public readonly reset = createEvent()
@@ -0,0 +1,75 @@
1
+ import { createEffect, createEvent, createStore, restore } from 'effector'
2
+ import { VoiceTranscriptionsCollection } from './VoiceTranscriptionsCollection'
3
+ import { VoicePlayerApi } from '../../types'
4
+ import { TranslationService } from '../../../translation/model/TranslationService'
5
+ import { GoogleTranslationProvider } from '../../../translation/providers/google/GoogleTranslationProvider'
6
+ import {
7
+ preservedWordsReplacers,
8
+ wordsToPreserve,
9
+ } from '../../../translation/preserve/wordsToPreserve'
10
+
11
+ type TranslateParams = {
12
+ attemptNumber: number
13
+ targetLanguage: string
14
+ }
15
+
16
+ type TranslateResult = {
17
+ attemptNumber: number
18
+ text: string
19
+ }
20
+
21
+ export class VoiceTranscriptionTranslationModel {
22
+ private readonly collection: VoiceTranscriptionsCollection
23
+ private readonly service: TranslationService
24
+
25
+ public readonly toggle = createEvent()
26
+ public readonly setActive = createEvent<boolean>()
27
+ public readonly clearCache = createEvent()
28
+ public readonly reset = createEvent()
29
+
30
+ public readonly $isActive = restore(this.setActive, false)
31
+ .on(this.toggle, (state) => !state)
32
+ .reset(this.reset)
33
+
34
+ public readonly translate = createEffect<TranslateParams, TranslateResult | null>(
35
+ async ({ attemptNumber, targetLanguage }) => {
36
+ const item = this.collection.get(attemptNumber)
37
+ if (!item?.transcript) return null
38
+
39
+ const text = await this.service.translate(item.transcript, {
40
+ targetLang: targetLanguage,
41
+ sourceLang: item.transcriptLanguage,
42
+ cacheKey: `voice::${attemptNumber}::${targetLanguage}`,
43
+ })
44
+
45
+ if (!text) return null
46
+
47
+ return { attemptNumber, text }
48
+ },
49
+ )
50
+
51
+ public readonly $translations = createStore<Record<number, string>>({})
52
+ .on(this.translate.doneData, (state, result) => {
53
+ if (!result) return state
54
+ return { ...state, [result.attemptNumber]: result.text }
55
+ })
56
+ .reset(this.reset, this.clearCache)
57
+
58
+ constructor(collection: VoiceTranscriptionsCollection, api: VoicePlayerApi) {
59
+ this.collection = collection
60
+ this.service = new TranslationService({
61
+ preserve: {
62
+ map: wordsToPreserve,
63
+ replacers: preservedWordsReplacers,
64
+ },
65
+ providers: [new GoogleTranslationProvider({ api: { translateRequest: api.translateText } })],
66
+ })
67
+
68
+ this.clearCache.watch(() => this.service.reset())
69
+ this.reset.watch(() => this.service.reset())
70
+ }
71
+
72
+ public getTranslation(attemptNumber: number): string | undefined {
73
+ return this.$translations.getState()[attemptNumber]
74
+ }
75
+ }
@@ -2,6 +2,12 @@ import { WithAbortSignal } from 'src/types/common.types'
2
2
  import { getAvailableInputs } from './helpers'
3
3
  import { VoiceRecordModel } from './recording/model/VoiceRecord.model'
4
4
  import { AxiosResponse } from 'axios'
5
+ import type {
6
+ GoogleTranslateProps as GoogleTranslatePayload,
7
+ GoogleTranslateResponse,
8
+ } from '../translation/providers/google.types'
9
+
10
+ export type { GoogleTranslatePayload, GoogleTranslateResponse }
5
11
 
6
12
  export type VoiceRecordNotificationTypes = {
7
13
  success: (message: string) => void
@@ -57,6 +63,7 @@ export type VoiceRecorderApi = {
57
63
  type TranscriptionStatus = 'pending' | 'completed' | 'failed'
58
64
  export type AudioTranscriptResponse = {
59
65
  text: string
66
+ language: string
60
67
  status: TranscriptionStatus
61
68
  }
62
69
 
@@ -66,6 +73,7 @@ export type VoicePlayerApi = {
66
73
  audioFileId: string,
67
74
  options?: { signal?: AbortSignal },
68
75
  ) => Promise<AxiosResponse<Blob>>
76
+ translateText: (payload: GoogleTranslatePayload) => Promise<GoogleTranslateResponse>
69
77
  }
70
78
 
71
79
  export type VoiceTranscriptionItem = {
@@ -73,6 +81,7 @@ export type VoiceTranscriptionItem = {
73
81
  audioFileId: string
74
82
  _id: string
75
83
  transcript?: string
84
+ transcriptLanguage?: string
76
85
  transcriptLoading?: boolean
77
86
  transcriptError?: string
78
87
  audioUri?: string
@@ -87,3 +96,9 @@ export enum RecordButtonVariant {
87
96
  DEFAULT = 'default',
88
97
  ADVANCED = 'advanced',
89
98
  }
99
+
100
+ export enum VoiceTranscriptionVariant {
101
+ SMALL = 'small',
102
+ LARGE = 'large',
103
+ }
104
+
package/src/index.ts CHANGED
@@ -14,3 +14,4 @@ export * from './shared/icons'
14
14
  export * from './features/voice'
15
15
  export * from './features/featureUsage'
16
16
  export * from './features/uiMode'
17
+ export * from './features/translation'