msedge tts
1.0.0
Cette bibliothèque est un emballage de l'API de la fonction à haute voix MSEdge Read . Vous pouvez l'utiliser pour synthétiser du texte pour parler avec de nombreuses voix fournies par MS.
SpeechConfig pour configurer la voix du texte vers la parole.Voice en SpeechConfig simplement. Utilisez la fonction get_voices_list pour obtenir toutes les voix disponibles.Voice et SpeechConfig ont mis en œuvre serde::Serialize et 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 par vous-même. Assurez-vous de connaître le bon nom de voix et le bon format audio .Client ou un Stream TTS. Tous deux ont une version synchronisée et asynchrone. Exemple ci-dessous Étape 3.synthesize pour synthétiser le texte en parole. Cette fonction renvoie le type SynthesizedAudio , vous pouvez obtenir audio_bytes et 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 pour synthétiser le texte en parole. Cette fonction renvoie le type SynthesizedAudio , vous pouvez obtenir audio_bytes et 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 pour synthétiser le texte à la parole. Fonction du flux du lecteur d'appel read pour obtenir des données.read Option<SynthesizedResponse> , la réponse peut être AudioBytes ou AudioMetadata ou aucune. En effet, l'API MSEdge Read Aloud renvoie plusieurs segments de données et des métadonnées et d'autres informations séquentiellement.send correspond à plusieurs read . Le prochain appel send bloquera jusqu'à ce qu'il n'y ait pas de données à lire. read va bloquer avant d'appeler un send . 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 pour synthétiser le texte à la parole. Fonction asynchrone du lecteur d'appel read pour obtenir des données. read Option<SynthesizedResponse> comme ci-dessus. send et read le bloc comme ci-dessus. 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" ) ;
}
}
}
}
} ) ;
}Voir tous les exemples.