@atmosx/event-product-parser 3.0.6 → 3.0.7

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 (181) hide show
  1. package/.github/docs/docs-functions.md +2 -2
  2. package/.github/docs/docs-general-configurations.md +2 -12
  3. package/.github/docs/docs-integrations.md +4 -3
  4. package/.github/docs/docs-listeners.md +1 -1
  5. package/.github/docs/docs-source-configuration.md +1 -1
  6. package/.github/docs/docs-technical.md +1 -1
  7. package/{.github/README.md → README.md} +15 -9
  8. package/dist/cjs/index.cjs +24073 -7018
  9. package/dist/esm/index.mjs +24035 -6983
  10. package/package.json +56 -47
  11. package/pnpm-workspace.yaml +4 -0
  12. package/src/bootstrap.ts +64 -48
  13. package/src/{@building → building}/CreateEvent.ts +22 -24
  14. package/src/{@building → building}/GetCleanedEvent.ts +2 -2
  15. package/src/{@building → building}/GetEventAttachments.ts +14 -12
  16. package/src/building/GetEventDirection.ts +28 -0
  17. package/src/{@building → building}/GetEventEnhancedName.ts +5 -8
  18. package/src/{@building → building}/GetEventGeometry.ts +19 -13
  19. package/src/{@building → building}/GetEventHeader.ts +13 -13
  20. package/src/{@building → building}/GetEventNodes.ts +21 -19
  21. package/src/{@building → building}/GetEventOffice.ts +13 -13
  22. package/src/building/GetEventProperties.ts +105 -0
  23. package/src/{@building → building}/GetEventSignature.ts +9 -9
  24. package/src/{@building → building}/GetEventTags.ts +3 -3
  25. package/src/building/GetEventTheme.ts +26 -0
  26. package/src/building/GetEventTracking.ts +64 -0
  27. package/src/components/audio/GenerateAudioMessage.ts +149 -0
  28. package/src/{@modules/@eas → components/audio/components}/GetCleanDescription.ts +2 -2
  29. package/src/{@modules/@eas → components/audio/components}/GetFloatPCM16.ts +2 -2
  30. package/src/{@modules/@eas → components/audio/components}/GetMergedPCM16.ts +2 -2
  31. package/src/{@modules/@eas → components/audio/components}/GetPCM16.ts +13 -8
  32. package/src/{@modules/@eas → components/audio/components}/GetPCMToFloat.ts +2 -2
  33. package/src/{@modules/@eas → components/audio/components}/GetSampledPCM16.ts +14 -8
  34. package/src/{@modules/@eas → components/audio/components}/GetTTS.ts +17 -10
  35. package/src/{@modules/@eas → components/audio/components}/GetWavPCM16.ts +7 -7
  36. package/src/{@modules/@eas → components/audio/components}/SetAFSK.ts +13 -8
  37. package/src/{@modules/@eas → components/audio/components}/SetAsciiToBits.ts +2 -2
  38. package/src/{@modules/@eas → components/audio/components}/SetAttentionTone.ts +11 -6
  39. package/src/{@modules/@eas → components/audio/components}/SetNoise.ts +12 -7
  40. package/src/{@modules/@eas → components/audio/components}/SetRadioEffect.ts +12 -7
  41. package/src/{@modules/@eas → components/audio/components}/SetSameHeader.ts +22 -14
  42. package/src/{@modules/@utilities/SetWarning.ts → components/database/CreateQuery.ts} +18 -13
  43. package/src/{@modules/@database → components/database}/GetCachedEvents.ts +18 -15
  44. package/src/components/database/ImportBoundaries.ts +168 -0
  45. package/src/{@modules/@database → components/database}/ImportBroadcastify.ts +14 -24
  46. package/src/components/database/ImportCities.ts +87 -0
  47. package/src/{@modules/@database → components/database}/ImportShapefiles.ts +23 -26
  48. package/src/{@modules/@database → components/database}/ImportStanza.ts +15 -19
  49. package/src/components/database/InitializeDatabase.ts +71 -0
  50. package/src/components/images/GenerateGraphic.ts +234 -0
  51. package/src/components/images/components/CreateRectangle.ts +22 -0
  52. package/src/components/images/components/CreateText.ts +22 -0
  53. package/src/components/images/modules/CreateSVG.ts +37 -0
  54. package/src/components/images/modules/GetGeographicalBoundaries.ts +72 -0
  55. package/src/components/images/modules/GetGeographicalCities.ts +58 -0
  56. package/src/components/images/modules/GetGeographicalEvents.ts +48 -0
  57. package/src/components/images/modules/GetGeometryBounds.ts +82 -0
  58. package/src/components/images/modules/GetParsedBoundary.ts +58 -0
  59. package/src/components/images/modules/GetSVGPath.ts +53 -0
  60. package/src/components/images/modules/NormalizePolygon.ts +57 -0
  61. package/src/{@modules/@stanza → components/stanza}/GetAwipsType.ts +16 -17
  62. package/src/{@modules/@stanza → components/stanza}/ValidateStanza.ts +27 -15
  63. package/src/{@modules/@utilities → components/utilities}/CreateHttp.ts +26 -26
  64. package/src/{@modules/@utilities → components/utilities}/GetFormattedTime.ts +2 -2
  65. package/src/{@modules/@utilities → components/utilities}/GetLatestIssuance.ts +2 -2
  66. package/src/{@modules/@utilities → components/utilities}/GetMatched.ts +10 -5
  67. package/src/{@modules/@utilities → components/utilities}/GetShapeNearestPoint.ts +24 -19
  68. package/src/components/utilities/GetUnionPolygon.ts +36 -0
  69. package/src/components/utilities/QueueManager.ts +70 -0
  70. package/src/{@modules/@utilities → components/utilities}/SetCronSchedule.ts +29 -25
  71. package/src/{@modules/@utilities → components/utilities}/SetDebug.ts +12 -12
  72. package/src/components/utilities/SetEventEmit.ts +42 -0
  73. package/src/{@modules/@utilities → components/utilities}/SetSettings.ts +7 -7
  74. package/src/{@modules/@utilities → components/utilities}/SetSleep.ts +5 -5
  75. package/src/components/utilities/SetTimeoutAction.ts +64 -0
  76. package/src/components/utilities/SetWarning.ts +47 -0
  77. package/src/{@modules/@xmpp → components/xmpp}/DeployXMPP.ts +20 -20
  78. package/src/{@core/CreateListener.ts → components/xmpp/ErrorXMPP.ts} +8 -5
  79. package/src/{@modules/@xmpp → components/xmpp}/OfflineXMPP.ts +13 -13
  80. package/src/{@modules/@xmpp → components/xmpp}/OnlineXMPP.ts +18 -18
  81. package/src/components/xmpp/ReconnectXMPP.ts +64 -0
  82. package/src/{@modules/@xmpp → components/xmpp}/StanzaXMPP.ts +25 -25
  83. package/src/{@core → core}/ClearEvents.ts +9 -9
  84. package/src/{@core → core}/GetEvents.ts +4 -4
  85. package/src/{@core → core}/GetNodes.ts +4 -4
  86. package/src/{@core → core}/GetRandomEvent.ts +4 -4
  87. package/src/{@core → core}/GetVersion.ts +4 -4
  88. package/src/{@core → core}/ManualEvent.ts +23 -24
  89. package/src/{@core → core}/QueryStanza.ts +12 -11
  90. package/src/core/SetNode.ts +87 -0
  91. package/src/{@core → core}/StartService.ts +21 -20
  92. package/src/{@core → core}/StopService.ts +10 -10
  93. package/src/{@enums → enums}/AWIPS.ts +2 -2
  94. package/src/{@enums → enums}/Actions.ts +2 -2
  95. package/src/{@enums → enums}/Cancellation.ts +2 -2
  96. package/src/{@enums → enums}/Causes.ts +2 -2
  97. package/src/{@enums → enums}/Correlations.ts +2 -2
  98. package/src/{@enums → enums}/Enhanced.ts +2 -2
  99. package/src/{@enums → enums}/Events.ts +2 -2
  100. package/src/{@enums → enums}/Expressions.ts +3 -3
  101. package/src/{@enums → enums}/GlobalFilter.ts +2 -2
  102. package/src/{@enums → enums}/Hail.ts +2 -2
  103. package/src/{@enums → enums}/ICAO.ts +2 -2
  104. package/src/{@enums → enums}/Matches.ts +8 -3
  105. package/src/{@enums → enums}/Products.ts +2 -2
  106. package/src/{@enums → enums}/Records.ts +2 -2
  107. package/src/{@enums → enums}/Severity.ts +2 -2
  108. package/src/{@enums → enums}/Shapefiles.ts +2 -2
  109. package/src/{@enums → enums}/States.ts +68 -4
  110. package/src/{@enums → enums}/Status.ts +2 -2
  111. package/src/{@enums → enums}/Strings.ts +2 -2
  112. package/src/{@enums → enums}/Tags.ts +9 -4
  113. package/src/{@enums → enums}/Testing.ts +2 -2
  114. package/src/enums/Themes.ts +70 -0
  115. package/src/events/ParseAPI.ts +129 -0
  116. package/src/{@events → events}/ParseText.ts +24 -22
  117. package/src/{@events → events}/ParseUGC.ts +27 -26
  118. package/src/{@events → events}/ParseVTEC.ts +38 -37
  119. package/src/index.ts +57 -37
  120. package/src/manager/MakeEvents.ts +110 -0
  121. package/src/manager/RemoveEvent.ts +74 -0
  122. package/src/{@manager → manager}/SetHash.ts +18 -13
  123. package/src/{@manager → manager}/UpdateEvents.ts +12 -12
  124. package/src/{@manager → manager}/UpdateNode.ts +14 -14
  125. package/src/{@building → manager}/ValidateEvents.ts +47 -57
  126. package/src/{@parsers/@hvtec → parsers/hvtec}/HVExtract.ts +11 -11
  127. package/src/{@parsers/@text → parsers/text}/GetDescriptionFromProduct.ts +20 -21
  128. package/src/{@parsers/@text → parsers/text}/GetEmbededText.ts +7 -6
  129. package/src/parsers/text/GetPolygonFromProduct.ts +71 -0
  130. package/src/{@parsers/@text → parsers/text}/GetStringText.ts +9 -9
  131. package/src/{@parsers/@text → parsers/text}/GetTextFromProduct.ts +12 -12
  132. package/src/parsers/ugc/GetCache.ts +24 -0
  133. package/src/{@parsers/@ugc → parsers/ugc}/GetExpiry.ts +2 -2
  134. package/src/{@parsers/@ugc/GetUGCHeader.ts → parsers/ugc/GetHeader.ts} +4 -4
  135. package/src/{@parsers/@ugc → parsers/ugc}/GetLocations.ts +10 -10
  136. package/src/parsers/ugc/GetZonePolygon.ts +73 -0
  137. package/src/{@parsers/@ugc → parsers/ugc}/GetZones.ts +3 -3
  138. package/src/{@parsers/@ugc → parsers/ugc}/SetCache.ts +13 -8
  139. package/src/{@parsers/@ugc → parsers/ugc}/UGCExtract.ts +14 -14
  140. package/src/{@parsers/@pvtec → parsers/vtec}/GetExpiry.ts +2 -2
  141. package/src/parsers/vtec/VTECExtract.ts +49 -0
  142. package/src/{@types → static}/Attributes.ts +2 -3
  143. package/src/{@types → static}/Event.ts +8 -7
  144. package/src/{@types → static}/Properties.ts +7 -3
  145. package/src/{@types → static}/Stanza.ts +2 -2
  146. package/src/tasks/CreateTasks.ts +123 -0
  147. package/src/tasks/TaskGenerateJSON.ts +34 -0
  148. package/src/tasks/TaskGenerateText.ts +34 -0
  149. package/src/tasks/TaskSendNTFY.ts +97 -0
  150. package/src/tasks/TaskSendWebhook.ts +107 -0
  151. package/src/{@types → types}/Actions.ts +3 -3
  152. package/src/{@types → types}/HVTEC.ts +6 -6
  153. package/src/{@types → types}/Hash.ts +5 -5
  154. package/src/types/Nodes.ts +29 -0
  155. package/src/{@types → types}/Settings.ts +16 -8
  156. package/src/{@types → types}/StanzaCompiled.ts +15 -15
  157. package/src/{@types → types}/UGC.ts +5 -5
  158. package/src/{@modules/@utilities/GetSettings.ts → types/VTEC.ts} +12 -7
  159. package/tools/build.js +47 -0
  160. package/tsconfig.json +28 -1
  161. package/src/@building/GetEventProperties.ts +0 -96
  162. package/src/@building/GetEventTracking.ts +0 -68
  163. package/src/@core/SetNode.ts +0 -81
  164. package/src/@events/ParseAPI.ts +0 -117
  165. package/src/@manager/CreateActions.ts +0 -213
  166. package/src/@manager/MakeEvent.ts +0 -99
  167. package/src/@manager/RemoveEvent.ts +0 -70
  168. package/src/@modules/@database/InitializeDatabase.ts +0 -59
  169. package/src/@modules/@eas/GenerateEASMessage.ts +0 -144
  170. package/src/@modules/@utilities/SetEventEmit.ts +0 -41
  171. package/src/@modules/@utilities/SetListener.ts +0 -30
  172. package/src/@modules/@utilities/SetTimeoutAction.ts +0 -64
  173. package/src/@modules/@xmpp/ErrorXMPP.ts +0 -27
  174. package/src/@modules/@xmpp/ReconnectXMPP.ts +0 -64
  175. package/src/@parsers/@pvtec/VTECExtract.ts +0 -49
  176. package/src/@parsers/@text/GetPolygonFromProduct.ts +0 -53
  177. package/src/@parsers/@text/GetXML.ts +0 -61
  178. package/src/@parsers/@ugc/GetCache.ts +0 -24
  179. package/src/@parsers/@ugc/GetZonePolygon.ts +0 -111
  180. package/src/@types/VTEC.ts +0 -30
  181. package/tsup.config.ts +0 -16
@@ -11,20 +11,20 @@
11
11
  Created with ♥ by the AtmosphericX Team (KiyoWx, StarflightWx, & CJ Ziegler)
12
12
  Discord: https://atmosphericx-discord.scriptkitty.cafe
13
13
  Ko-Fi: https://ko-fi.com/k3yomi
14
- Documentation: http://localhost/documentation | https://atmosphericx.scriptkitty.cafe/documentation
14
+ Documentation: https://atmosphericx.scriptkitty.cafe/documentation
15
15
 
16
- Internal Package: @atmosx/event-product-parser
16
+ Independent Package: @atmosx/event-product-parser
17
17
 
18
18
  */
19
19
 
20
- import { TypeAttributes } from "../@types/Attributes";
21
- import { TypePVTEC } from "../@types/VTEC";
22
- import { EnumICAO } from "../@enums/ICAO";
20
+ import { TypeAttributes } from "StaticTypes/Attributes"
21
+ import { TypeVTEC } from "Types/VTEC"
22
+ import { EnumICAO } from "@Enums/ICAO"
23
23
 
24
24
  interface GetOfficeOptions {
25
- attributes: TypeAttributes
26
- organization: string
27
- pVtec: TypePVTEC
25
+ Attributes: TypeAttributes
26
+ Organization: string
27
+ VTEC: TypeVTEC
28
28
  }
29
29
 
30
30
  interface GetOfficeResponse {
@@ -32,11 +32,11 @@ interface GetOfficeResponse {
32
32
  name: string | null
33
33
  }
34
34
 
35
- export const GetEventOffice = (options: GetOfficeOptions): GetOfficeResponse => {
36
- const office = options.pVtec != null
37
- ? options.pVtec?.tracking?.split(`.`)[0] : (options.attributes?.cccc ??
38
- (options.organization != null ?
39
- (Array.isArray(options.organization) ? options.organization?.[0] : options.organization)
35
+ export const GetEventOffice = ({ Attributes, Organization, VTEC }: GetOfficeOptions): GetOfficeResponse => {
36
+ const office = VTEC != null
37
+ ? VTEC?.Tracking?.split(`.`)[0] : (Attributes?.cccc ??
38
+ (Organization != null ?
39
+ (Array.isArray(Organization) ? Organization?.[0] : Organization)
40
40
  : null));
41
41
  const name = EnumICAO?.[office] ?? null;
42
42
  return { office, name };
@@ -0,0 +1,105 @@
1
+ /*
2
+ _ _ _ __ __
3
+ /\ | | | | (_) \ \ / /
4
+ / \ | |_ _ __ ___ ___ ___ _ __ | |__ ___ _ __ _ ___ \ V /
5
+ / /\ \| __| '_ ` _ \ / _ \/ __| '_ \| '_ \ / _ \ '__| |/ __| > <
6
+ / ____ \ |_| | | | | | (_) \__ \ |_) | | | | __/ | | | (__ / . \
7
+ /_/ \_\__|_| |_| |_|\___/|___/ .__/|_| |_|\___|_| |_|\___/_/ \_\
8
+ | |
9
+ |_|
10
+
11
+ Created with ♥ by the AtmosphericX Team (KiyoWx, StarflightWx, & CJ Ziegler)
12
+ Discord: https://atmosphericx-discord.scriptkitty.cafe
13
+ Ko-Fi: https://ko-fi.com/k3yomi
14
+ Documentation: https://atmosphericx.scriptkitty.cafe/documentation
15
+
16
+ Independent Package: @atmosx/event-product-parser
17
+
18
+ */
19
+
20
+ import { TypeEventProperties } from "StaticTypes/Properties"
21
+ import { TypeAttributes } from "StaticTypes/Attributes"
22
+ import { TypeUGC } from "Types/UGC"
23
+ import { TypeVTEC } from "Types/VTEC"
24
+ import { EnumExpressions } from "@Enums/Expressions"
25
+ import { GetDescriptionFromProduct } from "@ParsingText/GetDescriptionFromProduct"
26
+ import { GetPolygonFromProduct } from "@ParsingText/GetPolygonFromProduct"
27
+ import { GetTextFromProduct } from "@ParsingText/GetTextFromProduct"
28
+ import { GetEventOffice } from "@Building/GetEventOffice"
29
+ import { GetEventTags } from "@Building/GetEventTags"
30
+ import { GetEventDirection } from "@Building/GetEventDirection"
31
+
32
+ interface GetEventPropertiesOptions {
33
+ Message: string
34
+ Attributes: TypeAttributes
35
+ UGC?: TypeUGC
36
+ VTEC?: TypeVTEC
37
+ }
38
+
39
+ export const GetEventProperties = ({ Message, Attributes, UGC, VTEC }: GetEventPropertiesOptions): TypeEventProperties => {
40
+ const organization = Message.match(EnumExpressions.wmo)?.[0] ?? null
41
+ const polygons = GetPolygonFromProduct(Message)
42
+ const properties = {
43
+ locations: UGC?.Locations?.join(`; `) ?? null,
44
+ locations_array: UGC?.Locations ?? [],
45
+ regions: [...new Set(
46
+ UGC?.Zones
47
+ ?.map((location: string) => location.match(/^([A-Z]{2})[CZ](\d{3})$/)?.[1])
48
+ .filter(Boolean) ?? []
49
+ )],
50
+ regions_string: (() => {
51
+ const abbrs = [...new Set(UGC?.Zones?.map((l: string) => l.match(/^([A-Z]{2})[CZ](\d{3})$/)?.[1]).filter(Boolean) ?? [])];
52
+ return abbrs.length ? abbrs.join(`-`) : null;
53
+ })(),
54
+ description: GetDescriptionFromProduct({ Message: Message, Handle: VTEC?.Raw ?? null }),
55
+ attributes: Attributes,
56
+ geocode: {
57
+ office: GetEventOffice({ Attributes: Attributes, Organization: organization, VTEC: VTEC }),
58
+ organization: organization,
59
+ ugc: UGC?.Zones ?? [],
60
+ polygon: polygons.length > 0 ? Buffer.from(JSON.stringify([polygons])).toString('base64') : null,
61
+ polygon_generated: polygons.length > 0 ? true : false
62
+ },
63
+ parameters: {
64
+ tags: GetEventTags(Message),
65
+ instructions: GetTextFromProduct({ Message: Message, Find: [`For your protection`, `do not`, `use extreme caution`], Append: `...`, Removal: [`.`]}) ?? null,
66
+ source: GetTextFromProduct({ Message: Message, Find: [`SOURCE...`], Removal: [`.`]}) ?? null,
67
+ hazards: GetTextFromProduct({ Message: Message, Find: [`HAZARD...`], Removal: [`.`]}) ?? null,
68
+ impacts: GetTextFromProduct({ Message: Message, Find: [`IMPACT...`], Removal: [`.`]}) ?? null,
69
+ estimated_hail_size: GetTextFromProduct({ Message: Message, Find: [`MAX HAIL SIZE...`, `HAIL...`], Removal: ['in']}) ?? null,
70
+ estimated_wind_gusts: GetTextFromProduct({ Message: Message, Find: [`MAX WIND GUST...`, `WIND...`]}) ?? null,
71
+ direction: GetEventDirection(Message) ?? null,
72
+ damage_threat: GetTextFromProduct({ Message: Message, Find: [`DAMAGE THREAT...`], Removal: []}) ?? null,
73
+ tornado_threat: GetTextFromProduct({ Message: Message, Find: [`TORNADO...`, `WATERSPOUT...`] }) ?? null,
74
+ flood_threat: GetTextFromProduct({ Message: Message, Find: [`FLASH FLOOD...`]}) ?? null,
75
+ wind_threat: GetTextFromProduct({ Message: Message, Find: [`WIND THREAT...`]}) ?? null,
76
+ hail_threat: GetTextFromProduct({ Message: Message, Find: [`HAIL THREAT...`], Removal: []}) ?? null,
77
+ },
78
+ discussion_parameters: {
79
+ discussion_number: GetTextFromProduct({ Message: Message, Find: [`Mesoscale Discussion `], Removal: [`Mesoscale Discussion`, `Number`, `...`] })?.toString()?.padStart(4, "0") ?? null,
80
+ discussion_concerning: GetTextFromProduct({ Message: Message, Find: [`Concerning...`] }) ?? null,
81
+ discussion_max_tornado: GetTextFromProduct({ Message: Message, Find: [`MOST PROBABLE PEAK TORNADO INTENSITY...`] }) ?? null,
82
+ discussion_max_hail: GetTextFromProduct({ Message: Message, Find: [`MOST PROBABLE PEAK HAIL SIZE...`] }) ?? null,
83
+ discussion_max_wind: GetTextFromProduct({ Message: Message, Find: [`MOST PROBABLE PEAK WIND GUST...`] }) ?? null,
84
+ discussion_watch_issuance: GetTextFromProduct({ Message: Message, Find: [`Probability of Watch Issuance...`], Removal: [`percent`]}) ?? null,
85
+ },
86
+ watch_parameters: {
87
+ watch_number: VTEC?.Watch ? ( GetTextFromProduct({ Message: Message, Find: [`ITIES FOR`, `UPDATE FOR`, `Watch Number `], Removal: [`%`, `<`, `:`] })?.replace(/(WT|WS|)/g, '')?.trim()?.toString()?.padStart(4, "0") ?? VTEC?.Tracking?.slice(-4)?.toString()?.padStart(4, "0") ?? null) : null,
88
+ watch_type: Message.includes(`TORNADO WATCH`) ? `Tornado` : Message.includes(`SEVERE`) ? `Severe` : null,
89
+ additional_tornadoes_probability: GetTextFromProduct({ Message: Message, Find: [`PROB OF 2 OR MORE TORNADOES`], Removal: [`%`, `<`, `:`] }) ?? null,
90
+ strong_tornadoes_probability: GetTextFromProduct({ Message: Message, Find: [`PROB OF 1 OR MORE STRONG /EF2-EF5/ TORNADOES`], Removal: [`%`, `<`, `:`] }) ?? null,
91
+ severe_wind_probability: GetTextFromProduct({ Message: Message, Find: [`PROB OF 10 OR MORE SEVERE WIND EVENTS`], Removal: [`%`, `<`, `:`] }) ?? null,
92
+ severe_hail_probability: GetTextFromProduct({ Message: Message, Find: [`PROB OF 10 OR MORE SEVERE HAIL EVENTS`], Removal: [`%`, `<`, `:`] }) ?? null,
93
+ hail_2in_probability: GetTextFromProduct({ Message: Message, Find: [`PROB OF 1 OR MORE HAIL EVENTS >= 2 INCHES`], Removal: [`%`, `<`, `:`] }) ?? null,
94
+ combined_hail_wind_probability: GetTextFromProduct({ Message: Message, Find: [`PROB OF 6 OR MORE COMBINED SEVERE HAIL/WIND EVENTS`], Removal: [`%`, `<`, `:`] }) ?? null,
95
+ max_hail_in: GetTextFromProduct({ Message: Message, Find: [`MAX HAIL /INCHES/`], Removal: [`%`, `<`, `:`] }) ?? null,
96
+ max_wind_surface: GetTextFromProduct({ Message: Message, Find: [`MAX WIND GUSTS SURFACE /KNOTS/`], Removal: [`%`, `<`, `:`] }) ?? null,
97
+ max_tops_x100feet: GetTextFromProduct({ Message: Message, Find: [`MAX TOPS /X 100 FEET/`], Removal: [`%`, `<`, `:`] }) ?? null,
98
+ pds_watch: (GetTextFromProduct({ Message: Message, Find: [`PARTICULARLY DANGEROUS SITUATION`], Removal: [`%`, `<`, `:`] }) === `YES` ? true : null)
99
+ }
100
+ }
101
+ if (isNaN(Number(properties.watch_parameters.watch_number))) {
102
+ properties.watch_parameters.watch_number = null
103
+ }
104
+ return properties;
105
+ }
@@ -11,18 +11,18 @@
11
11
  Created with ♥ by the AtmosphericX Team (KiyoWx, StarflightWx, & CJ Ziegler)
12
12
  Discord: https://atmosphericx-discord.scriptkitty.cafe
13
13
  Ko-Fi: https://ko-fi.com/k3yomi
14
- Documentation: http://localhost/documentation | https://atmosphericx.scriptkitty.cafe/documentation
14
+ Documentation: https://atmosphericx.scriptkitty.cafe/documentation
15
15
 
16
- Internal Package: @atmosx/event-product-parser
16
+ Independent Package: @atmosx/event-product-parser
17
17
 
18
18
  */
19
19
 
20
- import { TypeEvent } from "../@types/Event";
21
- import { EnumCorrelations } from "../@enums/Correlations";
22
- import { EnumCancellation } from "../@enums/Cancellation";
23
- import { EnumTesting} from "../@enums/Testing"
24
- import { EnumProducts } from "../@enums/Products";
25
- import { EnumHail } from "../@enums/Hail"
20
+ import { TypeEvent } from "StaticTypes/Event"
21
+ import { EnumCorrelations } from "@Enums/Correlations"
22
+ import { EnumCancellation } from "@Enums/Cancellation"
23
+ import { EnumTesting} from "@Enums/Testing"
24
+ import { EnumProducts } from "@Enums/Products"
25
+ import { EnumHail } from "@Enums/Hail"
26
26
 
27
27
  export const GetEventSignature = (event: TypeEvent): TypeEvent => {
28
28
  const properties = event?.properties;
@@ -44,7 +44,7 @@ export const GetEventSignature = (event: TypeEvent): TypeEvent => {
44
44
  properties.status_metadata = { ...properties.status_metadata, is_expired: true };
45
45
  }
46
46
 
47
- const getProduct = vtec?.vtec?.split(`.`)[0]?.replace(`/`, ``)
47
+ const getProduct = vtec?.Raw?.split(`.`)[0]?.replace(`/`, ``)
48
48
  const isTestProduct = EnumProducts[getProduct] == `Test Product`
49
49
  if (isTestProduct || EnumTesting.some(sig => properties.description?.toLowerCase().includes(sig.toLowerCase()) ?? properties?.parameters?.instructions?.toLowerCase().includes(sig.toLowerCase()))) {
50
50
  properties.status_metadata = { ...properties.status_metadata, is_test: true }
@@ -11,13 +11,13 @@
11
11
  Created with ♥ by the AtmosphericX Team (KiyoWx, StarflightWx, & CJ Ziegler)
12
12
  Discord: https://atmosphericx-discord.scriptkitty.cafe
13
13
  Ko-Fi: https://ko-fi.com/k3yomi
14
- Documentation: http://localhost/documentation | https://atmosphericx.scriptkitty.cafe/documentation
14
+ Documentation: https://atmosphericx.scriptkitty.cafe/documentation
15
15
 
16
- Internal Package: @atmosx/event-product-parser
16
+ Independent Package: @atmosx/event-product-parser
17
17
 
18
18
  */
19
19
 
20
- import { EnumTags } from "../@enums/Tags";
20
+ import { EnumTags } from "@Enums/Tags"
21
21
 
22
22
  export const GetEventTags = (message: string): string[] => {
23
23
  if (!message) return [];
@@ -0,0 +1,26 @@
1
+ /*
2
+ _ _ _ __ __
3
+ /\ | | | | (_) \ \ / /
4
+ / \ | |_ _ __ ___ ___ ___ _ __ | |__ ___ _ __ _ ___ \ V /
5
+ / /\ \| __| '_ ` _ \ / _ \/ __| '_ \| '_ \ / _ \ '__| |/ __| > <
6
+ / ____ \ |_| | | | | | (_) \__ \ |_) | | | | __/ | | | (__ / . \
7
+ /_/ \_\__|_| |_| |_|\___/|___/ .__/|_| |_|\___|_| |_|\___/_/ \_\
8
+ | |
9
+ |_|
10
+
11
+ Created with ♥ by the AtmosphericX Team (KiyoWx, StarflightWx, & CJ Ziegler)
12
+ Discord: https://atmosphericx-discord.scriptkitty.cafe
13
+ Ko-Fi: https://ko-fi.com/k3yomi
14
+ Documentation: https://atmosphericx.scriptkitty.cafe/documentation
15
+
16
+ Independent Package: @atmosx/event-product-parser
17
+
18
+ */
19
+
20
+ import { Bootstrap } from "@Bootstrap";
21
+ import { EnumThemes } from "@Enums/Themes"
22
+ import { GetMatched } from "@Utilities/GetMatched";
23
+
24
+ export const GetEventTheme = (Event: string): string => {
25
+ return Bootstrap.Settings.GlobalSettings.Themes.find(theme => GetMatched({Strings: [theme.Event], String: Event}))?.RGB ?? EnumThemes.find(theme => theme.Event === `Default`)?.RGB ?? `rgb(56, 72, 88)`;
26
+ };
@@ -0,0 +1,64 @@
1
+ /*
2
+ _ _ _ __ __
3
+ /\ | | | | (_) \ \ / /
4
+ / \ | |_ _ __ ___ ___ ___ _ __ | |__ ___ _ __ _ ___ \ V /
5
+ / /\ \| __| '_ ` _ \ / _ \/ __| '_ \| '_ \ / _ \ '__| |/ __| > <
6
+ / ____ \ |_| | | | | | (_) \__ \ |_) | | | | __/ | | | (__ / . \
7
+ /_/ \_\__|_| |_| |_|\___/|___/ .__/|_| |_|\___|_| |_|\___/_/ \_\
8
+ | |
9
+ |_|
10
+
11
+ Created with ♥ by the AtmosphericX Team (KiyoWx, StarflightWx, & CJ Ziegler)
12
+ Discord: https://atmosphericx-discord.scriptkitty.cafe
13
+ Ko-Fi: https://ko-fi.com/k3yomi
14
+ Documentation: https://atmosphericx.scriptkitty.cafe/documentation
15
+
16
+ Independent Package: @atmosx/event-product-parser
17
+
18
+ */
19
+
20
+ import { TypeAttributes } from "StaticTypes/Attributes"
21
+ import { TypeEventProperties } from "StaticTypes/Properties"
22
+ import { TypeStanzaCompiled } from "Types/StanzaCompiled"
23
+ import { TypeVTEC } from "Types/VTEC"
24
+
25
+ interface GetTrackingOptions {
26
+ Type: `RAW` | `VTEC` | `API`
27
+ Stanza?: TypeStanzaCompiled
28
+ Attributes?: TypeAttributes
29
+ Properties?: TypeEventProperties
30
+ WMO?: {
31
+ Identifier: string
32
+ ID: string
33
+ }
34
+ VTEC?: TypeVTEC
35
+ }
36
+
37
+ export const GetEventTracking = ({ Type, Stanza, Attributes, Properties, WMO, VTEC }: GetTrackingOptions): string => {
38
+ if (Type === `RAW`) {
39
+ const getWatchNumber = Properties?.watch_parameters?.watch_number ?? null
40
+ if (getWatchNumber) {
41
+ return `${Properties.geocode.office.office}.${Stanza.Type.Prefix}.A.${getWatchNumber}`
42
+ }
43
+ return `${Properties.geocode.office.office}.${Attributes.ttaaii}.${Attributes.id.slice(-4).replace(`.`, ``) ?? '0'}`
44
+ }
45
+ if (Type === `VTEC`) {
46
+ return VTEC?.Tracking;
47
+ }
48
+ if (Type === `API`) {
49
+ if (VTEC) {
50
+ const vtecValue = Array.isArray(VTEC)
51
+ ? VTEC[0].vtec : VTEC?.Raw;
52
+ const splitVTEC = vtecValue.split('.');
53
+ return `${splitVTEC[2]}.${splitVTEC[3]}.${splitVTEC[4]}.${splitVTEC[5]}`;
54
+ }
55
+ const wmoMatch = WMO?.Identifier?.match(/([A-Z]{4}\d{2})\s+([A-Z]{4})/);
56
+ const station = wmoMatch?.[2] ?? '---';
57
+ if (WMO?.ID) {
58
+ const idMatch = WMO?.ID.match(/([a-f0-9]+)\.(\d+)\.(\d+)$/);
59
+ return `${station}.${idMatch?.[0]?.replace(/\./g, '') ?? '---'}`;
60
+ }
61
+ const id = wmoMatch?.[1] ?? '---';
62
+ return `${station}.${id?.replace(/\./g, '') ?? '---'}`;
63
+ }
64
+ }
@@ -0,0 +1,149 @@
1
+ /*
2
+ _ _ _ __ __
3
+ /\ | | | | (_) \ \ / /
4
+ / \ | |_ _ __ ___ ___ ___ _ __ | |__ ___ _ __ _ ___ \ V /
5
+ / /\ \| __| '_ ` _ \ / _ \/ __| '_ \| '_ \ / _ \ '__| |/ __| > <
6
+ / ____ \ |_| | | | | | (_) \__ \ |_) | | | | __/ | | | (__ / . \
7
+ /_/ \_\__|_| |_| |_|\___/|___/ .__/|_| |_|\___|_| |_|\___/_/ \_\
8
+ | |
9
+ |_|
10
+
11
+ Created with ♥ by the AtmosphericX Team (KiyoWx, StarflightWx, & CJ Ziegler)
12
+ Discord: https://atmosphericx-discord.scriptkitty.cafe
13
+ Ko-Fi: https://ko-fi.com/k3yomi
14
+ Documentation: https://atmosphericx.scriptkitty.cafe/documentation
15
+
16
+ Independent Package: @atmosx/event-product-parser
17
+
18
+ */
19
+
20
+ import { TypeSettings } from "Types/Settings"
21
+ import { Bootstrap } from "@Bootstrap"
22
+ import { GetWavPCM16 } from "@AudioComponents/GetWavPCM16"
23
+ import { GetSampledPCM16 } from "@AudioComponents/GetSampledPCM16"
24
+ import { SetRadioEffect } from "@AudioComponents/SetRadioEffect"
25
+ import { SetSameHeader } from "@AudioComponents/SetSameHeader"
26
+ import { SetAttentionTone } from "@AudioComponents/SetAttentionTone"
27
+ import { GetMergedPCM16 } from "@AudioComponents/GetMergedPCM16"
28
+ import { SetNoise } from "@AudioComponents/SetNoise"
29
+ import { GetPCM16 } from "@AudioComponents/GetPCM16"
30
+ import { GetTTS } from "@AudioComponents/GetTTS"
31
+ import { GetCleanDescription } from "@AudioComponents/GetCleanDescription"
32
+ import { SetWarning } from "@Utilities/SetWarning"
33
+ import { SetDebug } from "@Utilities/SetDebug"
34
+ import { join } from "path"
35
+ import { existsSync, mkdirSync, readFileSync, writeFileSync, unlinkSync } from "fs"
36
+ import { execSync } from "child_process"
37
+ import { platform } from "os"
38
+
39
+ interface GenerateAudioMessageOptions {
40
+ Message: string
41
+ Header: string
42
+ Directory?: string
43
+ Title: string
44
+ }
45
+
46
+ export const GenerateAudioMessage = async ({ Message, Directory, Header, Title }: GenerateAudioMessageOptions): Promise<string> => {
47
+ const tick = performance.now()
48
+ const settings = Bootstrap.Settings as TypeSettings;
49
+ const prefix = settings.GlobalSettings.ArchiveSettings.AudioToneout;
50
+ let title = (Title ?? `${Math.random().toString(36).substring(2, 15)}-${Header.replace(/[^a-zA-Z0-9]/g, '')}`).replace(/[\\:*?"<>|]/g, "_").replace(/\s+/g, " ").trim();
51
+ if (!Message || !Header) {
52
+ SetWarning({
53
+ Title: `Audio`,
54
+ Message: `Message and header are required to generate an audio message.`
55
+ })
56
+ return null;
57
+ }
58
+ let buffTTS: Buffer;
59
+ let buffRadio: any;
60
+ let buffFull: any[] = [];
61
+
62
+ if (!Directory) {
63
+ SetWarning({
64
+ Title: `Audio`,
65
+ Message: `Audio directory is not set in the settings. Please set it to generate audio messages.`
66
+ });
67
+ return null;
68
+ }
69
+
70
+ if (!existsSync(Directory)) {
71
+ mkdirSync(Directory, { recursive: true });
72
+ }
73
+ const tmpTTS = join(Directory, `/${title}-tts.wav`)
74
+ const outTTS = join(Directory, `/${title}.wav`)
75
+ const vPlatform = platform();
76
+
77
+ if (vPlatform === 'darwin') {
78
+ SetWarning({
79
+ Title: `Audio`,
80
+ Message: `Audio tone generation is not supported on macOS.`
81
+ });
82
+ return null
83
+ }
84
+
85
+
86
+ await new Promise<void>((resolve, reject) => {
87
+ const tMsg = GetCleanDescription(Message)
88
+ GetTTS({Text: tMsg, OutputPath: tmpTTS}).then(() => {
89
+ resolve();
90
+ });
91
+ });
92
+ if (!existsSync(tmpTTS)) {
93
+ return null;
94
+ }
95
+ buffTTS = readFileSync(tmpTTS);
96
+ const vWav = GetWavPCM16(buffTTS);
97
+ const vSamples = GetSampledPCM16({Int16: vWav.Samples, OriginalRate: vWav.SampleRate, TargetRate: 8000})
98
+ const vRadio = SetRadioEffect({Int16: vSamples, SampleRate: 8000});
99
+
100
+ if (existsSync(prefix)) {
101
+ let tBuffer = readFileSync(prefix);
102
+ let tWav = GetWavPCM16(tBuffer);
103
+
104
+ if (tWav == null) {
105
+ try {
106
+ const converted = join(Directory, `/${title}-tts-fixed.wav`)
107
+ execSync(`ffmpeg -y -i "${prefix}" -ar 8000 -ac 1 -sample_fmt s16 "${converted}"`, { stdio: 'ignore' })
108
+ if (existsSync(converted)) {
109
+ tBuffer = readFileSync(converted)
110
+ tWav = GetWavPCM16(tBuffer)
111
+ try { unlinkSync(converted) } catch {}
112
+ }
113
+ } catch (e) {}
114
+ }
115
+
116
+ if (tWav == null) {
117
+ SetWarning({
118
+ Title: `EAS`,
119
+ Message: `Intro tone isn't a valid .WAV file or isn't in PCM 16-bit format. Converted attempt failed; please convert it then try again.`
120
+ })
121
+ return null;
122
+ }
123
+
124
+ const tSamples = (tWav.SampleRate != 8000 ? GetSampledPCM16({Int16: tWav.Samples, OriginalRate: tWav.SampleRate, TargetRate: 8000}) : tWav.Samples)
125
+ buffRadio = SetRadioEffect({Int16: tSamples, SampleRate: 8000})
126
+ }
127
+
128
+ buffFull = buffRadio != null ? [buffRadio, new Int16Array(Math.floor(0.5 * 8000))] : [];
129
+ buffFull.push(
130
+ SetSameHeader({ VTEC: Header, Repeats: 3, SampleRate: 8000, PreMarkSec: 1.1, GapSec: 0.5 }),
131
+ new Int16Array(Math.floor(0.5 * 8000)),
132
+ SetAttentionTone({ MS: 8, SampleRate: 8000 }),
133
+ new Int16Array(Math.floor(0.5 * 8000)),
134
+ vRadio
135
+ )
136
+ for (let i = 0; i < 3; i++) {
137
+ buffFull.push(SetSameHeader({ VTEC: Header, Repeats: 1, SampleRate: 8000, PreMarkSec: 0.5, GapSec: 0.1 }))
138
+ buffFull.push(new Int16Array(Math.floor(0.5 * 8000)));
139
+ }
140
+ const aSamples = GetMergedPCM16(buffFull);
141
+ const aFinal = SetNoise({ Int16: aSamples, NoiseLevel: 0.002 });
142
+ const aBuffer = GetPCM16({ Samples: Array.from(aFinal).map(v => ({ value: v })), SampleRate: 8000 });
143
+ writeFileSync(outTTS, aBuffer)
144
+ try{ unlinkSync(tmpTTS) } catch {}
145
+ SetDebug({ Title: `GenerateEASMessage`, Message: `${Math.round(performance.now() - tick)}ms` })
146
+ return outTTS;
147
+ }
148
+
149
+
@@ -11,9 +11,9 @@
11
11
  Created with ♥ by the AtmosphericX Team (KiyoWx, StarflightWx, & CJ Ziegler)
12
12
  Discord: https://atmosphericx-discord.scriptkitty.cafe
13
13
  Ko-Fi: https://ko-fi.com/k3yomi
14
- Documentation: http://localhost/documentation | https://atmosphericx.scriptkitty.cafe/documentation
14
+ Documentation: https://atmosphericx.scriptkitty.cafe/documentation
15
15
 
16
- Internal Package: @atmosx/event-product-parser
16
+ Independent Package: @atmosx/event-product-parser
17
17
 
18
18
 
19
19
  */
@@ -11,9 +11,9 @@
11
11
  Created with ♥ by the AtmosphericX Team (KiyoWx, StarflightWx, & CJ Ziegler)
12
12
  Discord: https://atmosphericx-discord.scriptkitty.cafe
13
13
  Ko-Fi: https://ko-fi.com/k3yomi
14
- Documentation: http://localhost/documentation | https://atmosphericx.scriptkitty.cafe/documentation
14
+ Documentation: https://atmosphericx.scriptkitty.cafe/documentation
15
15
 
16
- Internal Package: @atmosx/event-product-parser
16
+ Independent Package: @atmosx/event-product-parser
17
17
 
18
18
 
19
19
  */
@@ -11,9 +11,9 @@
11
11
  Created with ♥ by the AtmosphericX Team (KiyoWx, StarflightWx, & CJ Ziegler)
12
12
  Discord: https://atmosphericx-discord.scriptkitty.cafe
13
13
  Ko-Fi: https://ko-fi.com/k3yomi
14
- Documentation: http://localhost/documentation | https://atmosphericx.scriptkitty.cafe/documentation
14
+ Documentation: https://atmosphericx.scriptkitty.cafe/documentation
15
15
 
16
- Internal Package: @atmosx/event-product-parser
16
+ Independent Package: @atmosx/event-product-parser
17
17
 
18
18
 
19
19
  */
@@ -11,19 +11,24 @@
11
11
  Created with ♥ by the AtmosphericX Team (KiyoWx, StarflightWx, & CJ Ziegler)
12
12
  Discord: https://atmosphericx-discord.scriptkitty.cafe
13
13
  Ko-Fi: https://ko-fi.com/k3yomi
14
- Documentation: http://localhost/documentation | https://atmosphericx.scriptkitty.cafe/documentation
14
+ Documentation: https://atmosphericx.scriptkitty.cafe/documentation
15
15
 
16
- Internal Package: @atmosx/event-product-parser
16
+ Independent Package: @atmosx/event-product-parser
17
17
 
18
18
 
19
19
  */
20
20
 
21
- export const GetPCM16 = (samples: Record<string, number>[], sampleRate: number): Buffer => {
21
+ interface GetPCM16Options {
22
+ Samples: Record<string, number>[]
23
+ SampleRate: number
24
+ }
25
+
26
+ export const GetPCM16 = ({ Samples, SampleRate }: GetPCM16Options): Buffer => {
22
27
  let o = 0;
23
28
  const bytesPerSample = 2;
24
29
  const blockAlign = 1 * bytesPerSample;
25
- const byteRate = sampleRate * blockAlign;
26
- const subchunk2Size = samples.length * bytesPerSample;
30
+ const byteRate = SampleRate * blockAlign;
31
+ const subchunk2Size = Samples.length * bytesPerSample;
27
32
  const chunkSize = 36 + subchunk2Size;
28
33
  const buffer = Buffer.alloc(44 + subchunk2Size);
29
34
 
@@ -35,7 +40,7 @@ export const GetPCM16 = (samples: Record<string, number>[], sampleRate: number):
35
40
  buffer.writeUInt32LE(16, o); o += 4;
36
41
  buffer.writeUInt16LE(1, o); o += 2;
37
42
  buffer.writeUInt16LE(1, o); o += 2;
38
- buffer.writeUInt32LE(sampleRate, o); o += 4;
43
+ buffer.writeUInt32LE(SampleRate, o); o += 4;
39
44
  buffer.writeUInt32LE(byteRate, o); o += 4;
40
45
  buffer.writeUInt16LE(blockAlign, o); o += 2;
41
46
  buffer.writeUInt16LE(16, o); o += 2;
@@ -43,8 +48,8 @@ export const GetPCM16 = (samples: Record<string, number>[], sampleRate: number):
43
48
  buffer.write("data", o); o += 4;
44
49
  buffer.writeUInt32LE(subchunk2Size, o); o += 4;
45
50
 
46
- for (let i = 0; i < samples.length; i++, o += 2) {
47
- buffer.writeInt16LE(samples[i].value, o);
51
+ for (let i = 0; i < Samples.length; i++, o += 2) {
52
+ buffer.writeInt16LE(Samples[i].value, o);
48
53
  }
49
54
  return buffer;
50
55
  }
@@ -11,9 +11,9 @@
11
11
  Created with ♥ by the AtmosphericX Team (KiyoWx, StarflightWx, & CJ Ziegler)
12
12
  Discord: https://atmosphericx-discord.scriptkitty.cafe
13
13
  Ko-Fi: https://ko-fi.com/k3yomi
14
- Documentation: http://localhost/documentation | https://atmosphericx.scriptkitty.cafe/documentation
14
+ Documentation: https://atmosphericx.scriptkitty.cafe/documentation
15
15
 
16
- Internal Package: @atmosx/event-product-parser
16
+ Independent Package: @atmosx/event-product-parser
17
17
 
18
18
 
19
19
  */
@@ -11,24 +11,30 @@
11
11
  Created with ♥ by the AtmosphericX Team (KiyoWx, StarflightWx, & CJ Ziegler)
12
12
  Discord: https://atmosphericx-discord.scriptkitty.cafe
13
13
  Ko-Fi: https://ko-fi.com/k3yomi
14
- Documentation: http://localhost/documentation | https://atmosphericx.scriptkitty.cafe/documentation
14
+ Documentation: https://atmosphericx.scriptkitty.cafe/documentation
15
15
 
16
- Internal Package: @atmosx/event-product-parser
16
+ Independent Package: @atmosx/event-product-parser
17
17
 
18
18
 
19
19
  */
20
20
 
21
- export const GetSampledPCM16 = (int16: Int16Array, originalRate: number, targetRate: number): Int16Array => {
22
- if (originalRate === targetRate) return int16;
23
- const ratio = targetRate / originalRate;
24
- const outLen = Math.max(1, Math.round(int16.length * ratio));
21
+ interface GetSampledPCM16Options {
22
+ Int16: Int16Array
23
+ OriginalRate: number
24
+ TargetRate: number
25
+ }
26
+
27
+ export const GetSampledPCM16 = ({ Int16, OriginalRate, TargetRate }: GetSampledPCM16Options): Int16Array => {
28
+ if (OriginalRate === TargetRate) return Int16;
29
+ const ratio = TargetRate / OriginalRate;
30
+ const outLen = Math.max(1, Math.round(Int16.length * ratio));
25
31
  const out = new Int16Array(outLen);
26
32
  for (let i = 0; i < outLen; i++) {
27
33
  const pos = i / ratio;
28
34
  const i0 = Math.floor(pos);
29
- const i1 = Math.min(i0 + 1, int16.length - 1);
35
+ const i1 = Math.min(i0 + 1, Int16.length - 1);
30
36
  const frac = pos - i0;
31
- const v = int16[i0] * (1 - frac) + int16[i1] * frac;
37
+ const v = Int16[i0] * (1 - frac) + Int16[i1] * frac;
32
38
  out[i] = Math.round(v);
33
39
  }
34
40
  return out;
@@ -11,33 +11,40 @@
11
11
  Created with ♥ by the AtmosphericX Team (KiyoWx, StarflightWx, & CJ Ziegler)
12
12
  Discord: https://atmosphericx-discord.scriptkitty.cafe
13
13
  Ko-Fi: https://ko-fi.com/k3yomi
14
- Documentation: http://localhost/documentation | https://atmosphericx.scriptkitty.cafe/documentation
14
+ Documentation: https://atmosphericx.scriptkitty.cafe/documentation
15
15
 
16
- Internal Package: @atmosx/event-product-parser
16
+ Independent Package: @atmosx/event-product-parser
17
17
 
18
18
 
19
19
  */
20
20
 
21
- import { platform } from 'os'
22
- import { writeFileSync } from "fs"
23
- import { execSync } from 'child_process'
21
+ import { platform } from "os"
22
+ import { writeFileSync, unlinkSync} from "fs"
23
+ import { execSync } from "child_process"
24
24
 
25
- export const GetTTS = async (text: string, outputPath: string): Promise<void> => {
25
+
26
+ interface GetTTSOptions {
27
+ Text: string
28
+ OutputPath: string
29
+ }
30
+
31
+ export const GetTTS = async ({ Text, OutputPath }: GetTTSOptions): Promise<void> => {
26
32
  const vPlatform = platform();
27
33
  switch (vPlatform) {
28
34
  case 'win32': {
29
35
  try {
30
- const txtPath = outputPath + ".txt";
31
- writeFileSync(txtPath, text, "utf8");
36
+ const txtPath = OutputPath + ".txt";
37
+ writeFileSync(txtPath, Text, "utf8");
32
38
  const command = [
33
39
  "Add-Type -AssemblyName System.Speech;",
34
40
  `$speak = New-Object System.Speech.Synthesis.SpeechSynthesizer;`,
35
41
  `$text = Get-Content -Raw -LiteralPath '${txtPath}';`,
36
- `$speak.SetOutputToWaveFile('${outputPath}');`,
42
+ `$speak.SetOutputToWaveFile('${OutputPath}');`,
37
43
  `$speak.Speak($text);`,
38
44
  `$speak.Dispose();`
39
45
  ].join(" ");
40
46
  execSync(`powershell -Command "${command}"`, { stdio: 'inherit' })
47
+ try{ unlinkSync(txtPath) } catch {}
41
48
  } catch(error) {
42
49
  console.error('Error occurred while generating TTS:', error);
43
50
  }
@@ -45,7 +52,7 @@ export const GetTTS = async (text: string, outputPath: string): Promise<void> =>
45
52
  }
46
53
  case 'linux':
47
54
  try {
48
- execSync(`espeak -w "${outputPath}" "${text.replace(/"/g, '\\"')}"`);
55
+ execSync(`espeak -w "${OutputPath}" "${Text.replace(/"/g, '\\"')}"`);
49
56
  } catch {}
50
57
  break;
51
58
  default: break;