@@ -40,7 +40,7 @@ enum KokoroChunker {
4040 hasLanguageToken: Bool ,
4141 allowedPhonemes: Set < String > ,
4242 phoneticOverrides: [ TtsPhoneticOverride ]
43- ) throws -> [ TextChunk ] {
43+ ) async throws -> [ TextChunk ] {
4444 let trimmed = text. trimmingCharacters ( in: . whitespacesAndNewlines)
4545 guard !trimmed. isEmpty else { return [ ] }
4646
@@ -60,7 +60,7 @@ enum KokoroChunker {
6060 return [ ]
6161 }
6262
63- let mergedSentences = try mergeShortSentences (
63+ let mergedSentences = try await mergeShortSentences (
6464 refinedSentences,
6565 lexicon: wordToPhonemes,
6666 caseSensitiveLexicon: caseSensitiveLexicon,
@@ -74,7 +74,7 @@ enum KokoroChunker {
7474 segmentsByPunctuations. reserveCapacity ( segmentsByPeriods. count)
7575
7676 for (periodIndex, segment) in segmentsByPeriods. enumerated ( ) {
77- let count = try tokenCountForSegment (
77+ let count = try await tokenCountForSegment (
7878 for: segment,
7979 lexicon: wordToPhonemes,
8080 caseSensitiveLexicon: caseSensitiveLexicon,
@@ -84,7 +84,7 @@ enum KokoroChunker {
8484
8585 if count > capacity {
8686 let fragments = splitByPunctuation ( segment)
87- let reassembled = try reassembleFragments (
87+ let reassembled = try await reassembleFragments (
8888 fragments,
8989 lexicon: wordToPhonemes,
9090 caseSensitiveLexicon: caseSensitiveLexicon,
@@ -120,7 +120,7 @@ enum KokoroChunker {
120120 chunks. reserveCapacity ( segmentsByPunctuations. count)
121121
122122 for chunkText in segmentsByPunctuations {
123- let built = try buildChunks (
123+ let built = try await buildChunks (
124124 from: chunkText,
125125 lexicon: wordToPhonemes,
126126 caseSensitiveLexicon: caseSensitiveLexicon,
@@ -181,7 +181,7 @@ enum KokoroChunker {
181181 caseSensitiveLexicon: [ String : [ String ] ] ,
182182 allowed: Set < String > ,
183183 capacity: Int
184- ) throws -> [ String ] {
184+ ) async throws -> [ String ] {
185185 guard !sentences. isEmpty else { return [ ] }
186186
187187 let threshold = max ( 1 , min ( capacity, TtsConstants . shortSentenceMergeTokenThreshold) )
@@ -203,7 +203,7 @@ enum KokoroChunker {
203203 let trimmed = sentence. trimmingCharacters ( in: . whitespacesAndNewlines)
204204 guard !trimmed. isEmpty else { continue }
205205
206- let sentenceTokens = try tokenCountForSegment (
206+ let sentenceTokens = try await tokenCountForSegment (
207207 for: trimmed,
208208 lexicon: lexicon,
209209 caseSensitiveLexicon: caseSensitiveLexicon,
@@ -231,7 +231,7 @@ enum KokoroChunker {
231231 }
232232
233233 let candidate = appendSegment ( buffer, with: trimmed)
234- let candidateTokens = try tokenCountForSegment (
234+ let candidateTokens = try await tokenCountForSegment (
235235 for: candidate,
236236 lexicon: lexicon,
237237 caseSensitiveLexicon: caseSensitiveLexicon,
@@ -270,7 +270,7 @@ enum KokoroChunker {
270270 wordIndex: inout Int ,
271271 overrides: [ TtsPhoneticOverride ] ,
272272 overrideIndex: inout Int
273- ) throws -> [ TextChunk ] {
273+ ) async throws -> [ TextChunk ] {
274274 let atoms = tokenizeAtoms ( text)
275275 guard !atoms. isEmpty else { return [ ] }
276276
@@ -345,7 +345,7 @@ enum KokoroChunker {
345345
346346 if resolved == nil {
347347 guard
348- let fallback = try resolvePhonemes (
348+ let fallback = try await resolvePhonemes (
349349 for: original,
350350 normalized: normalized,
351351 lexicon: lexicon,
@@ -482,7 +482,7 @@ enum KokoroChunker {
482482 caseSensitiveLexicon: [ String : [ String ] ] ,
483483 allowed: Set < String > ,
484484 missing: inout Set < String >
485- ) throws -> [ String ] ? {
485+ ) async throws -> [ String ] ? {
486486 var phonemes = caseSensitiveLexicon [ original]
487487
488488 if phonemes == nil , let exactNormalized = caseSensitiveLexicon [ normalized] {
@@ -493,7 +493,7 @@ enum KokoroChunker {
493493 phonemes = lexicon [ normalized]
494494 }
495495
496- if phonemes == nil , let ipa = try EspeakG2P . shared. phonemize ( word: normalized) {
496+ if phonemes == nil , let ipa = try await EspeakG2P . shared. phonemize ( word: normalized) {
497497 let mapped = PhonemeMapper . mapIPA ( ipa, allowed: allowed)
498498 if !mapped. isEmpty {
499499 phonemes = mapped
@@ -510,7 +510,7 @@ enum KokoroChunker {
510510 for spelled in spelledTokens {
511511 var segment = lexicon [ spelled]
512512
513- if segment == nil , let ipa = try EspeakG2P . shared. phonemize ( word: spelled) {
513+ if segment == nil , let ipa = try await EspeakG2P . shared. phonemize ( word: spelled) {
514514 let mapped = PhonemeMapper . mapIPA ( ipa, allowed: allowed)
515515 if !mapped. isEmpty {
516516 segment = mapped
@@ -574,7 +574,7 @@ enum KokoroChunker {
574574 caseSensitiveLexicon: [ String : [ String ] ] ,
575575 allowed: Set < String > ,
576576 capacity: Int
577- ) throws -> Int {
577+ ) async throws -> Int {
578578 let atoms = tokenizeAtoms ( text)
579579 guard !atoms. isEmpty else { return 0 }
580580
@@ -589,7 +589,7 @@ enum KokoroChunker {
589589 let normalized = normalize ( original)
590590 guard !normalized. isEmpty else { continue }
591591 guard
592- let phonemes = try resolvePhonemes (
592+ let phonemes = try await resolvePhonemes (
593593 for: original,
594594 normalized: normalized,
595595 lexicon: lexicon,
@@ -625,7 +625,7 @@ enum KokoroChunker {
625625 caseSensitiveLexicon: [ String : [ String ] ] ,
626626 allowed: Set < String > ,
627627 capacity: Int
628- ) throws -> [ String ] {
628+ ) async throws -> [ String ] {
629629 guard !fragments. isEmpty else { return [ ] }
630630
631631 var assembled : [ String ] = [ ]
@@ -647,7 +647,7 @@ enum KokoroChunker {
647647 current. isEmpty
648648 ? trimmedFragment
649649 : appendSegment ( current, with: trimmedFragment)
650- let candidateTokens = try tokenCountForSegment (
650+ let candidateTokens = try await tokenCountForSegment (
651651 for: candidate,
652652 lexicon: lexicon,
653653 caseSensitiveLexicon: caseSensitiveLexicon,
@@ -660,7 +660,7 @@ enum KokoroChunker {
660660 } else {
661661 flushCurrent ( )
662662 current = trimmedFragment
663- let fragmentTokens = try tokenCountForSegment (
663+ let fragmentTokens = try await tokenCountForSegment (
664664 for: current,
665665 lexicon: lexicon,
666666 caseSensitiveLexicon: caseSensitiveLexicon,
0 commit comments