msedge tts
1.0.0
Esta biblioteca é um invólucro da API de função de leitura em voz alta . Você pode usá -lo para sintetizar o texto para falar com muitas vozes que MS fornecidos.
SpeechConfig para configurar a voz do texto para a fala.Voice em SpeechConfig simplesmente. Use a função get_voices_list para obter todas as vozes disponíveis.Voice e SpeechConfig implementaram serde::Serialize e 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 sozinho. Certifique -se de saber o nome da voz certo e o formato de áudio .Client ou Stream TTS. Ambos têm uma versão sincronizada e assíncrona. Exemplo abaixo da etapa 3.synthesize para sintetizar o texto com a fala. Esta função Return Type SynthesizedAudio , você pode obter audio_bytes e 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 o texto com a fala. Esta função Return Type SynthesizedAudio , você pode obter audio_bytes e 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 para sintetizar o texto para o discurso. Função de fluxo do leitor de chamadas read para obter dados.read Option<SynthesizedResponse> , a resposta pode ser AudioBytes ou AudioMetadata ou nenhuma. Isso ocorre porque a API de leitura em voz alta retorna vários segmentos de dados e metadados e outras informações sequencialmente.send corresponde a várias read . Em seguida, a chamada send será bloqueada até que não haja dados para ler. read será bloqueada antes de ligar para o 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 para sintetizar o texto para o discurso. Função Async Reader Async read para obter dados. read Option<SynthesizedResponse> como acima. send e read o bloco como acima. 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" ) ;
}
}
}
}
} ) ;
}Veja todos os exemplos.