zoom_video_sdk_live_transcription.js 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. import { ZoomVideoSDKErrors } from './zoom_video_sdk_defines.js'
  2. import messages from './electron_zoomvideosdk_pb.js'
  3. import { setUserInfo } from './zoom_video_sdk_user_util.js'
  4. export default (function () {
  5. var instance
  6. /**
  7. * live transcription helper.
  8. * @module zoom_video_sdk_live_transcription
  9. * @return {ZoomVideoSDKLiveTranscription}
  10. */
  11. function init (opts) {
  12. const clientOpts = {...opts}
  13. // Private methods and variables
  14. if (!clientOpts.addon) {
  15. return null
  16. }
  17. const _addon = clientOpts.addon.GetLiveTranscriptionHelper()
  18. return {
  19. // Public methods and variables
  20. /**
  21. * Query if the user can start live transcription.
  22. * @method canStartLiveTranscription
  23. * @return {Boolean}
  24. */
  25. canStartLiveTranscription: function () {
  26. if (_addon) {
  27. try {
  28. return _addon.CanStartLiveTranscription()
  29. } catch (error) {
  30. return ZoomVideoSDKErrors.ZoomVideoSDKErrors_Invalid_Parameter;
  31. }
  32. }
  33. return ZoomVideoSDKErrors.ZoomVideoSDKErrors_Internal_Error
  34. },
  35. /**
  36. * Get the current live transcription status.
  37. * @method getLiveTranscriptionStatus
  38. * @return {Object} the current live transcription status. For more details, see {@link ZoomVideoSDKLiveTranscriptionStatus} enum.
  39. */
  40. getLiveTranscriptionStatus: function () {
  41. if (_addon) {
  42. try {
  43. return _addon.GetLiveTranscriptionStatus()
  44. } catch (error) {
  45. return ZoomVideoSDKErrors.ZoomVideoSDKErrors_Invalid_Parameter;
  46. }
  47. }
  48. return ZoomVideoSDKErrors.ZoomVideoSDKErrors_Internal_Error
  49. },
  50. /**
  51. * If the session allows multi-language transcription, all users can start live transcription.
  52. * @method startLiveTranscription
  53. * @return {Number} If the function succeed, the return value is ZoomVideoSDKErrors_Success.
  54. Otherwise failed. To get extended error information, {@link ZoomVideoSDKErrors} enum.
  55. */
  56. startLiveTranscription: function () {
  57. if (_addon) {
  58. try {
  59. return _addon.StartLiveTranscription()
  60. } catch (error) {
  61. return ZoomVideoSDKErrors.ZoomVideoSDKErrors_Invalid_Parameter;
  62. }
  63. }
  64. return ZoomVideoSDKErrors.ZoomVideoSDKErrors_Internal_Error
  65. },
  66. /**
  67. * If the session allows multi-language transcription,all users can stop live transcription.
  68. * @method stopLiveTranscription
  69. * @return {Number} If the function succeed, the return value is ZoomVideoSDKErrors_Success.
  70. Otherwise failed. To get extended error information, {@link ZoomVideoSDKErrors} enum.
  71. */
  72. stopLiveTranscription: function () {
  73. if (_addon) {
  74. try {
  75. return _addon.StopLiveTranscription()
  76. } catch (error) {
  77. return ZoomVideoSDKErrors.ZoomVideoSDKErrors_Invalid_Parameter;
  78. }
  79. }
  80. return ZoomVideoSDKErrors.ZoomVideoSDKErrors_Internal_Error
  81. },
  82. /**
  83. * Get the list of all available spoken languages in session.
  84. * @method getAvailableSpokenLanguages
  85. * @return {Array} If the function succeeds, the return value is the list of the available spoken languages in a session. Otherwise failed, the return value is NULL.
  86. */
  87. getAvailableSpokenLanguages: function () {
  88. if (_addon) {
  89. try {
  90. const result = _addon.GetAvailableSpokenLanguages()
  91. const message = new messages.LTTLanguagesList.deserializeBinary(result)
  92. const tempList = message.getLttlanguageinfoList()
  93. let lttLanguageList = []
  94. for (let val of tempList) {
  95. let obj = {
  96. lttLanguageID: val.getLttlanguageid(),
  97. lttLanguageName: val.getLttlanguagename()
  98. }
  99. lttLanguageList.push(obj)
  100. }
  101. return lttLanguageList
  102. } catch (error) {
  103. return ZoomVideoSDKErrors.ZoomVideoSDKErrors_Invalid_Parameter;
  104. }
  105. }
  106. return ZoomVideoSDKErrors.ZoomVideoSDKErrors_Internal_Error
  107. },
  108. /**
  109. * Get the list of all available translation languages in a session.
  110. * @method GetAvailableTranslationLanguages
  111. * @return {Array} If the function succeeds, the return value is the list of all available translation languages in a session. Otherwise failed, the return value is NULL.
  112. */
  113. getAvailableTranslationLanguages: function () {
  114. if (_addon) {
  115. try {
  116. const result = _addon.GetAvailableTranslationLanguages()
  117. const message = new messages.LTTLanguagesList.deserializeBinary(result)
  118. const tempList = message.getLttlanguageinfoList()
  119. let lttLanguageList = []
  120. for (let val of tempList) {
  121. let obj = {
  122. lttLanguageID: val.getLttlanguageid(),
  123. lttLanguageName: val.getLttlanguagename()
  124. }
  125. lttLanguageList.push(obj)
  126. }
  127. return lttLanguageList
  128. } catch (error) {
  129. return ZoomVideoSDKErrors.ZoomVideoSDKErrors_Invalid_Parameter;
  130. }
  131. }
  132. return ZoomVideoSDKErrors.ZoomVideoSDKErrors_Internal_Error
  133. },
  134. /**
  135. * Set the spoken language of the current user.
  136. * @method setSpokenLanguage
  137. * @param {Number} languageID The spoken language ID.
  138. * @return {Number} If the function succeed, the return value is ZoomVideoSDKErrors_Success.
  139. Otherwise failed. To get extended error information, {@link ZoomVideoSDKErrors} enum.
  140. */
  141. setSpokenLanguage: function (opts) {
  142. if (_addon) {
  143. const clientOpts = {...opts}
  144. try {
  145. const languageID = clientOpts.languageID
  146. const SetSpokenLanguageParams = new messages.SetSpokenLanguageParams()
  147. SetSpokenLanguageParams.setLanguageid(languageID)
  148. const bytes = SetSpokenLanguageParams.serializeBinary()
  149. return _addon.SetSpokenLanguage(bytes)
  150. } catch (error) {
  151. return ZoomVideoSDKErrors.ZoomVideoSDKErrors_Invalid_Parameter;
  152. }
  153. }
  154. return ZoomVideoSDKErrors.ZoomVideoSDKErrors_Internal_Error
  155. },
  156. /**
  157. * Set the translation language of the current user.
  158. * @method setTranslationLanguage
  159. * @param {Number} languageID The translation language ID. If the language id is set to -1, live translation will be disabled.
  160. * @return {Number} If the function succeed, the return value is ZoomVideoSDKErrors_Success.
  161. Otherwise failed. To get extended error information, {@link ZoomVideoSDKErrors} enum.
  162. */
  163. setTranslationLanguage: function (opts) {
  164. if (_addon) {
  165. const clientOpts = {...opts}
  166. try {
  167. const languageID = clientOpts.languageID
  168. const SetTranslationLanguageParams = new messages.SetTranslationLanguageParams()
  169. SetTranslationLanguageParams.setLanguageid(languageID)
  170. const bytes = SetTranslationLanguageParams.serializeBinary()
  171. return _addon.SetTranslationLanguage(bytes)
  172. } catch (error) {
  173. return ZoomVideoSDKErrors.ZoomVideoSDKErrors_Invalid_Parameter;
  174. }
  175. }
  176. return ZoomVideoSDKErrors.ZoomVideoSDKErrors_Internal_Error
  177. },
  178. /**
  179. * Get the spoken language of the current user.
  180. * @method getSpokenLanguage
  181. * @return {Object} If the function succeed, the return value is ZoomVideoSDKErrors_Success.
  182. Otherwise failed. To get extended error information, {@link ZoomVideoSDKErrors} enum.
  183. */
  184. getSpokenLanguage: function () {
  185. if (_addon) {
  186. try {
  187. return _addon.GetSpokenLanguage()
  188. } catch (error) {
  189. return ZoomVideoSDKErrors.ZoomVideoSDKErrors_Invalid_Parameter;
  190. }
  191. }
  192. return ZoomVideoSDKErrors.ZoomVideoSDKErrors_Internal_Error
  193. },
  194. /**
  195. * Get the translation language of the current user.
  196. * @method getTranslationLanguage
  197. * @return {Object} If the function succeed, the return value is ZoomVideoSDKErrors_Success.
  198. Otherwise failed. To get extended error information, {@link ZoomVideoSDKErrors} enum.
  199. */
  200. getTranslationLanguage: function () {
  201. if (_addon) {
  202. try {
  203. return _addon.GetTranslationLanguage()
  204. } catch (error) {
  205. return ZoomVideoSDKErrors.ZoomVideoSDKErrors_Invalid_Parameter;
  206. }
  207. }
  208. return ZoomVideoSDKErrors.ZoomVideoSDKErrors_Internal_Error
  209. }
  210. }
  211. };
  212. return {
  213. getInstance: function (opts) {
  214. if (!instance) {
  215. instance = init(opts)
  216. }
  217. return instance
  218. }
  219. }
  220. })()