msedge tts
1.0.0
Diese Bibliothek ist ein Wrapper der MSEDSE -API -Funktionsfunktions -API. Sie können es verwenden, um Text zur Sprache mit vielen zur Verfügung gestellten Stimmen zu synthetisieren.
SpeechConfig erhalten, um die Stimme des Textes mit Sprache zu konfigurieren.Voice einfach in SpeechConfig umwandeln. Verwenden Sie get_voices_list -Funktion, um alle verfügbaren Stimmen zu erhalten.Voice and SpeechConfig implementiert serde::Serialize und serde::Deserialize . use msedge_tts :: voice :: get_voices_list ;
use msedge_tts :: tts :: SpeechConfig ;
fn main ( ) {
let voices = get_voices_list ( ) . unwrap ( ) ;
let speechConfig = SpeechConfig :: from ( & voices [ 0 ] ) ;
}SpeechConfig erstellen. Stellen Sie sicher, dass Sie den richtigen Sprachnamen und das Audio -Format kennen.Client oder einen TTS Stream . Beide haben eine synchronisierende und asynchronisierte Version. Beispiel unten Schritt 3.synthesize , um Text mit Sprache zu synthetisieren. Dieser Funktionsrückgabe -Typ SynthesizedAudio erhalten Sie von audio_bytes und audio_metadata . use msedge_tts :: { tts :: client :: connect , tts :: SpeechConfig , voice :: get_voices_list } ;
fn main ( ) {
let voices = get_voices_list ( ) . unwrap ( ) ;
for voice in & voices {
if voice . name . contains ( "YunyangNeural" ) {
let config = SpeechConfig :: from ( voice ) ;
let mut tts = connect ( ) . unwrap ( ) ;
let audio = tts
. synthesize ( "Hello, World! 你好,世界!" , & config )
. unwrap ( ) ;
break ;
}
}
}synthesize , um Text mit Sprache zu synthetisieren. Dieser Funktionsrückgabe -Typ SynthesizedAudio erhalten Sie von audio_bytes und audio_metadata . use msedge_tts :: { tts :: client :: connect_async , tts :: SpeechConfig , voice :: get_voices_list_async } ;
fn main ( ) {
smol :: block_on ( async {
let voices = get_voices_list_async ( ) . await . unwrap ( ) ;
for voice in & voices {
if voice . name . contains ( "YunyangNeural" ) {
let config = SpeechConfig :: from ( voice ) ;
let mut tts = connect_async ( ) . await . unwrap ( ) ;
let audio = tts
. synthesize ( "Hello, World! 你好,世界!" , & config )
. await
. unwrap ( ) ;
break ;
}
}
} ) ;
}send . Rufen Sie die Leser -Stream -Funktion auf read um Daten zu erhalten.Option<SynthesizedResponse> read AudioBytes AudioMetadata Dies liegt daran, dass die MSDEDS -ACI -API mehrere Datensegments und Metadaten und andere Informationen nacheinander zurückgibt.send entspricht mehreren read . Als nächstes send den Anruf, bis keine Daten zu lesen sind. read blockiert, bevor Sie einen send anrufen. use msedge_tts :: {
tts :: stream :: { msedge_tts_split , SynthesizedResponse } ,
tts :: SpeechConfig ,
voice :: get_voices_list ,
} ;
use std :: {
sync :: {
atomic :: { AtomicBool , Ordering } ,
Arc ,
} ,
thread :: spawn ,
} ;
fn main ( ) {
let voices = get_voices_list ( ) . unwrap ( ) ;
for voice in & voices {
if voice . name . contains ( "YunyangNeural" ) {
let config = SpeechConfig :: from ( voice ) ;
let ( mut sender , mut reader ) = msedge_tts_split ( ) . unwrap ( ) ;
let signal = Arc :: new ( AtomicBool :: new ( false ) ) ;
let end = signal . clone ( ) ;
spawn ( move || {
sender . send ( "Hello, World! 你好,世界!" , & config ) . unwrap ( ) ;
println ! ( "synthesizing...1" ) ;
sender . send ( "Hello, World! 你好,世界!" , & config ) . unwrap ( ) ;
println ! ( "synthesizing...2" ) ;
sender . send ( "Hello, World! 你好,世界!" , & config ) . unwrap ( ) ;
println ! ( "synthesizing...3" ) ;
sender . send ( "Hello, World! 你好,世界!" , & config ) . unwrap ( ) ;
println ! ( "synthesizing...4" ) ;
end . store ( true , Ordering :: Relaxed ) ;
} ) ;
loop {
if signal . load ( Ordering :: Relaxed ) && !reader . can_read ( ) {
break ;
}
let audio = reader . read ( ) . unwrap ( ) ;
if let Some ( audio ) = audio {
match audio {
SynthesizedResponse :: AudioBytes ( _ ) => {
println ! ( "read bytes" )
}
SynthesizedResponse :: AudioMetadata ( _ ) => {
println ! ( "read metadata" )
}
}
} else {
println ! ( "read None" ) ;
}
}
}
}
}send , um Text an die Sprache zu synthetisieren. Rufen Sie den Leser Async -Funktion read um Daten zu erhalten. read die Rückgabeoption Option<SynthesizedResponse> wie oben. send und read Block wie oben. use msedge_tts :: {
tts :: {
stream :: { msedge_tts_split_async , SynthesizedResponse } ,
SpeechConfig ,
} ,
voice :: get_voices_list_async ,
} ;
use std :: {
sync :: {
atomic :: { AtomicBool , Ordering } ,
Arc ,
} ,
} ;
fn main ( ) {
smol :: block_on ( async {
let voices = get_voices_list_async ( ) . await . unwrap ( ) ;
for voice in & voices {
if voice . name . contains ( "YunyangNeural" ) {
let config = SpeechConfig :: from ( voice ) ;
let ( mut sender , mut reader ) = msedge_tts_split_async ( ) . await . unwrap ( ) ;
let signal = Arc :: new ( AtomicBool :: new ( false ) ) ;
let end = signal . clone ( ) ;
smol :: spawn ( async move {
sender
. send ( "Hello, World! 你好,世界!" , & config )
. await
. unwrap ( ) ;
println ! ( "synthesizing...1" ) ;
sender
. send ( "Hello, World! 你好,世界!" , & config )
. await
. unwrap ( ) ;
println ! ( "synthesizing...2" ) ;
sender
. send ( "Hello, World! 你好,世界!" , & config )
. await
. unwrap ( ) ;
println ! ( "synthesizing...3" ) ;
sender
. send ( "Hello, World! 你好,世界!" , & config )
. await
. unwrap ( ) ;
println ! ( "synthesizing...4" ) ;
end . store ( true , Ordering :: Relaxed ) ;
} )
. detach ( ) ;
loop {
if signal . load ( Ordering :: Relaxed ) && !reader . can_read ( ) . await {
break ;
}
let audio = reader . read ( ) . await . unwrap ( ) ;
if let Some ( audio ) = audio {
match audio {
SynthesizedResponse :: AudioBytes ( _ ) => {
println ! ( "read bytes" )
}
SynthesizedResponse :: AudioMetadata ( _ ) => {
println ! ( "read metadata" )
}
}
} else {
println ! ( "read None" ) ;
}
}
}
}
} ) ;
}Siehe alle Beispiele.