-
Notifications
You must be signed in to change notification settings - Fork 451
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add HarmonyOS support for text-to-speech. (#1584)
- Loading branch information
1 parent
a3d6e1a
commit dc3287f
Showing
33 changed files
with
333 additions
and
133 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
harmony-os/SherpaOnnxHar/sherpa_onnx/src/main/ets/components/NonStreamingTts.ets
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import { | ||
createOfflineTts, | ||
getOfflineTtsNumSpeakers, | ||
getOfflineTtsSampleRate, | ||
offlineTtsGenerate, | ||
} from "libsherpa_onnx.so"; | ||
|
||
export class OfflineTtsVitsModelConfig { | ||
public model: string = ''; | ||
public lexicon: string = ''; | ||
public tokens: string = ''; | ||
public dataDir: string = ''; | ||
public dictDir: String = ''; | ||
public noiseScale: number = 0.667; | ||
public noiseScaleW: number = 0.8; | ||
public lengthScale: number = 1.0; | ||
} | ||
|
||
export class OfflineTtsModelConfig{ | ||
public vits: OfflineTtsVitsModelConfig = new OfflineTtsVitsModelConfig(); | ||
public numThreads: number = 1; | ||
public debug: boolean = false; | ||
public provider: string = 'cpu'; | ||
} | ||
|
||
export class OfflineTtsConfig{ | ||
public model: OfflineTtsModelConfig = new OfflineTtsModelConfig(); | ||
public ruleFsts: string = ''; | ||
public ruleFars: string = ''; | ||
public maxNumSentences: number = 1; | ||
} | ||
|
||
export class TtsOutput { | ||
public samples: Float32Array = new Float32Array(0); | ||
public sampleRate: number = 0; | ||
} | ||
|
||
export class TtsInput { | ||
public text: string = ''; | ||
public sid: number = 0; | ||
public speed: number = 1.0; | ||
} | ||
|
||
export class OfflineTts { | ||
private handle: object; | ||
public config: OfflineTtsConfig; | ||
public numSpeakers: number; | ||
public sampleRate: number; | ||
constructor(config: OfflineTtsConfig, mgr?: object) { | ||
this.handle = createOfflineTts(config, mgr); | ||
this.config = config; | ||
|
||
this.numSpeakers = getOfflineTtsNumSpeakers(this.handle); | ||
this.sampleRate = getOfflineTtsSampleRate(this.handle); | ||
} | ||
|
||
/* | ||
input obj: {text: "xxxx", sid: 0, speed: 1.0} | ||
where text is a string, sid is a int32, speed is a float | ||
|
||
return an object {samples: Float32Array, sampleRate: <a number>} | ||
*/ | ||
generate(input: TtsInput): TtsOutput { | ||
return offlineTtsGenerate(this.handle, input) as TtsOutput; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.