msedge tts
1.0.0
Esta biblioteca es un envoltorio de la API de la función de lectura de msedge en voz alta . Puede usarlo para sintetizar el texto al habla con muchas voces proporcionadas.
SpeechConfig para configurar la voz del texto al habla.Voice a SpeechConfig simplemente. Use la función get_voices_list para obtener todas las voces disponibles.Voice and SpeechConfig implementado serde::Serialize y 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 por ti mismo. Asegúrese de conocer el nombre de voz y el formato de audio correctos.Client o Stream TTS. Ambos tienen una versión de sincronización y asíncrata. Ejemplo a continuación Paso 3.synthesize para sintetizar el texto al habla. Este tipo de función de retorno SynthesizedAudio , puede obtener audio_bytes y 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 para sintetizar el texto al habla. Este tipo de función de retorno SynthesizedAudio , puede obtener audio_bytes y 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 al texto sintetizar al discurso. Llame a la función de transmisión del lector read para obtener datos.read Option<SynthesizedResponse> , la respuesta puede ser AudioBytes o AudioMetadata o ninguno. Esto se debe a que la API de MSEDGE en voz alta devuelve múltiples segmentos de datos y metadatos y otra información secuencialmente.send corresponde a read múltiple. La próxima llamada send se bloqueará hasta que no haya datos para leer. read Bloqueará antes de llamar a 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 al texto sintetizar al discurso. Llame a la función Async del lector read para obtener datos. read Option<SynthesizedResponse> como se indicó anteriormente. send y read bloque como arriba. 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" ) ;
}
}
}
}
} ) ;
}ver todos los ejemplos.