Skip to content

Commit b7b04fb

Browse files
committed
wip + fix
1 parent 427a83d commit b7b04fb

File tree

39 files changed

+2045
-7299
lines changed

39 files changed

+2045
-7299
lines changed

Cargo.lock

Lines changed: 959 additions & 4824 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/tts/components-rust/test-tts/src/lib.rs

Lines changed: 8 additions & 288 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,11 @@ use crate::bindings::exports::test::tts_exports::test_tts_api::*;
88
use crate::bindings::test::helper_client::test_helper_client::TestHelperApi;
99

1010
use crate::bindings::golem::tts::advanced::{convert_voice, design_voice, generate_sound_effect, AgeCategory, OperationStatus, VoiceDesignParams};
11-
use crate::bindings::golem::tts::streaming::StreamStatus;
1211
use crate::bindings::golem::tts::synthesis::{AudioEffects, SynthesisResult, VoiceSettings};
1312
use crate::bindings::golem::tts::{
1413
advanced::{
1514
create_lexicon, create_voice_clone, synthesize_long_form, AudioSample, PronunciationEntry,
1615
},
17-
streaming::{create_stream, create_voice_conversion_stream},
1816
synthesis::{get_timing_marks, synthesize, synthesize_batch, validate_input, SynthesisOptions},
1917
types::{AudioConfig, TextInput, TextType, VoiceGender, TtsError},
2018
voices::{get_voice, list_languages, Voice, VoiceFilter},
@@ -91,7 +89,7 @@ impl Guest for Component {
9189

9290

9391
// Test Getting a specific voice
94-
fn test2() -> String {
92+
fn test1() -> String {
9593
trace!("Getting a specific voice.");
9694
match get_voice(VOICE_UUID) {
9795
Ok(voice) => {
@@ -105,7 +103,7 @@ impl Guest for Component {
105103
}
106104

107105
// Test Synthesizing text
108-
fn test4() -> String {
106+
fn test2() -> String {
109107
let voice = match get_voice(VOICE_UUID) {
110108
Ok(voices) => voices,
111109
Err(err) => {
@@ -232,7 +230,7 @@ impl Guest for Component {
232230
}
233231

234232
// Test Synthesizing text with SSML
235-
fn test5() -> String {
233+
fn test3() -> String {
236234
let voice = match get_voice(VOICE_UUID) {
237235
Ok(voices) => voices,
238236
Err(err) => {
@@ -269,7 +267,7 @@ impl Guest for Component {
269267
}
270268

271269
// Test Batch synthesis for multiple inputs
272-
fn test6() -> String {
270+
fn test4() -> String {
273271
let voice = match get_voice(VOICE_UUID) {
274272
Ok(voices) => voices,
275273
Err(err) => {
@@ -319,7 +317,7 @@ impl Guest for Component {
319317
}
320318

321319
// Test Validate text before synthesis & Get timing information without audio synthesis
322-
fn test7() -> String {
320+
fn test5() -> String {
323321
let voice = match get_voice(VOICE_UUID) {
324322
Ok(voices) => voices,
325323
Err(err) => {
@@ -380,290 +378,12 @@ impl Guest for Component {
380378
test_result
381379
}
382380

383-
// 💥💥 Test durable synthesis streaming
384-
fn test8() -> String {
385-
trace!("Testing durable synthesis streaming...");
386-
let voice = match get_voice(VOICE_UUID) {
387-
Ok(voices) => voices,
388-
Err(err) => {
389-
return format!("❌ ERROR : {:?}", err);
390-
}
391-
};
392-
393-
let mut test_result = String::new();
394-
test_result.push_str("Test synthesis streaming summary:\n");
395-
396-
let options = SynthesisOptions{
397-
audio_config: None,
398-
voice_settings: None,
399-
audio_effects: None,
400-
enable_timing: None,
401-
enable_word_timing: None,
402-
seed: None,
403-
model_id: Some(MODEL.to_string()),
404-
context: None,
405-
};
406-
407-
trace!("Creating stream for speech synthesis.");
408-
let test_name = "Test synthesis streaming";
409-
let stream = match create_stream(&voice, Some(&options)) {
410-
Ok(stream) => {
411-
trace!("Stream created successfully. ✅\n",);
412-
test_result.push_str("1. Test create stream ✅\n");
413-
stream
414-
}
415-
Err(err) => {
416-
trace!("Failed to create stream. ❌\n",);
417-
test_result.push_str("1. Test create stream ❌\n");
418-
test_result.push_str(&format!("ERROR : {:?}\n", err));
419-
test_result.push_str(&format!("{test_name} ❌\n"));
420-
return test_result;
421-
}
422-
};
423-
424-
let agent_name =
425-
std::env::var("GOLEM_AGENT_NAME").unwrap_or_else(|_| "test-agent".to_string());
426-
427-
trace!("Sending text as chunks for synthesis.");
428-
// Sending text as chunks
429-
for text in "In a quiet coastal village, mornings begin with the scent of salt in the air and the rhythm of waves meeting the shore.".split_whitespace() {
430-
431-
432-
mimic_crash(&agent_name);
433-
434-
let input = TextInput {
435-
content: text.to_string(),
436-
text_type: TextType::Plain,
437-
language: Some("en-US".to_string()),
438-
};
439-
440-
match stream.send_text(&input) {
441-
Ok(_) => {
442-
trace!("Text sent successfully. ✅\n",);
443-
}
444-
Err(err) => {
445-
trace!("Failed to send text. ❌\n",);
446-
trace!("Sending failed at {text}\n",);
447-
test_result.push_str("2. Test send text ❌\n");
448-
test_result.push_str(&format!("ERROR : {:?}\n", err));
449-
test_result.push_str(&format!("{test_name} ❌\n"));
450-
return test_result;
451-
}
452-
};
453-
}
454-
test_result.push_str("2. Test send text ✅\n");
455-
456-
match stream.finish() {
457-
Ok(_) => {
458-
trace!("Text sending finished successfully. ✅\n",);
459-
test_result.push_str("3. Test finish stream ✅\n");
460-
}
461-
Err(err) => {
462-
trace!("Failed to finish stream. ❌\n",);
463-
test_result.push_str("3. Test finish stream ❌\n");
464-
test_result.push_str(&format!("ERROR : {:?}\n", err));
465-
test_result.push_str(&format!("{test_name} ❌\n"));
466-
return test_result;
467-
}
468-
}
469-
470-
trace!("Reciving audio chunks.");
471-
let mut audio_data = Vec::new();
472-
let mut chunk_count = 0;
473-
let max_attempts = 30;
474-
let mut attempts = 0;
475-
476-
while attempts < max_attempts {
477-
if !stream.has_pending_audio() && matches!(stream.get_status(), StreamStatus::Finished)
478-
{
479-
break;
480-
}
481-
482-
if chunk_count == 7{
483-
trace!("Crashing when receiving audio chunks #{chunk_count}.");
484-
mimic_crash(&agent_name);
485-
}
486-
487-
match stream.receive_chunk() {
488-
Ok(Some(chunk)) => {
489-
trace!("Recieved chunk #{chunk_count}\n");
490-
audio_data.extend_from_slice(&chunk.data);
491-
chunk_count += 1;
492-
if chunk.is_final {
493-
break;
494-
}
495-
}
496-
Ok(None) => {
497-
trace!("No chunk available. Retrying...\n");
498-
thread::sleep(Duration::from_millis(100));
499-
}
500-
Err(e) => {
501-
trace!("Failed to receive chunk #{chunk_count}. ❌\n");
502-
test_result.push_str(&format!("4. Test receive chunk ❌\n"));
503-
test_result.push_str(&format!("ERROR : {:?}\n", e));
504-
test_result.push_str(&format!("{test_name} ❌\n"));
505-
break;
506-
}
507-
}
508-
509-
// Just as edge case
510-
if attempts == 10 {
511-
trace!("Crashing when receiving audio chunks after 10 attempts.");
512-
mimic_crash(&agent_name);
513-
}
514-
515-
attempts += 1;
516-
}
517-
518-
test_result.push_str("4. Test receive chunk ✅\n");
519-
520-
521-
trace!("Saving audio data.");
522-
if !audio_data.is_empty() {
523-
let dir = "/test-audio-files";
524-
let name = "test8-synthesis-streaming.mp3";
525-
save_audio(&audio_data, dir, name);
526-
trace!("Audio saved at {dir}/{name} 💾\n");
527-
test_result.push_str(&format!("Audio saved at {dir}/{name} 💾\n"));
528-
529-
}
530-
531-
trace!("Closing stream...\n");
532-
stream.close();
533-
trace!("Stream closed successfully. ✅\n",);
534-
test_result.push_str("5. Test close stream ✅\n");
535-
test_result.push_str(&format!("{test_name} ✅\n"));
536-
537-
test_result
538-
539-
}
540-
541-
// 💥💥💥 Test durable voice conversion
542-
fn test9() -> String {
543-
let voice = match get_voice(VOICE_UUID) {
544-
Ok(voices) => voices,
545-
Err(err) => {
546-
return format!("❌ ERROR : {:?}", err);
547-
}
548-
};
549-
550-
let mut test_result = String::new();
551-
test_result.push_str("Test synthesis streaming summary:\n");
552-
553-
trace!("Creating stream for speech synthesis.");
554-
let test_name = "Test voice conversion streaming";
555-
let stream = match create_voice_conversion_stream(&voice, None) {
556-
Ok(stream) => {
557-
trace!("Stream created successfully. ✅\n",);
558-
test_result.push_str("1. Test create stream ✅\n");
559-
stream
560-
}
561-
Err(err) => {
562-
trace!("Failed to create stream. ❌\n",);
563-
test_result.push_str("1. Test create stream ❌\n");
564-
test_result.push_str(&format!("ERROR : {:?}\n", err));
565-
test_result.push_str(&format!("{test_name} ❌\n"));
566-
return test_result;
567-
}
568-
};
569-
570-
let agent_name =
571-
std::env::var("GOLEM_AGENT_NAME").unwrap_or_else(|_| "test-agent".to_string());
572-
573-
let voice_data = fs::read("/test-audio-files/test4-audio-config.mp3").unwrap();
574-
trace!("Sending voice data.");
575-
match stream.send_audio(&voice_data) {
576-
Ok(_) => {
577-
trace!("Audio sent successfully. ✅\n",);
578-
test_result.push_str("2. Test send audio data ✅\n");
579-
}
580-
Err(err) => {
581-
trace!("Failed to send audio. ❌\n",);
582-
test_result.push_str("2. Test send audio data ❌\n");
583-
test_result.push_str(&format!("ERROR : {:?}\n", err));
584-
test_result.push_str(&format!("{test_name} ❌\n"));
585-
return test_result;
586-
}
587-
}
588-
589-
trace!("Crashing after sending audio data.");
590-
mimic_crash(&agent_name);
591-
592-
trace!("Finishing stream.");
593-
match stream.finish() {
594-
Ok(_) => {
595-
trace!("Stream finished successfully. ✅\n",);
596-
test_result.push_str("3. Test finish stream ✅\n");
597-
}
598-
Err(err) => {
599-
trace!("Failed to finish stream. ❌\n",);
600-
test_result.push_str("3. Test finish stream ❌\n");
601-
test_result.push_str(&format!("ERROR : {:?}\n", err));
602-
test_result.push_str(&format!("{test_name} ❌\n"));
603-
return test_result;
604-
}
605-
}
606-
607-
trace!("Crashing after finishing stream before receiving converted audio chunks.");
608-
mimic_crash(&agent_name);
609-
610-
trace!("Reciving audio chunks.");
611-
let mut converted_audio_data = Vec::new();
612-
let max_attempts = 30;
613-
let mut attempts = 0;
614-
while attempts < max_attempts {
615-
616-
if attempts == 7 {
617-
trace!("Crashing when receiving converted audio chunks after 6th attempts.");
618-
mimic_crash(&agent_name);
619-
}
620-
621-
match stream.receive_converted() {
622-
Ok(Some(chunk)) => {
623-
trace!("Recieved converted voice\n");
624-
converted_audio_data.extend_from_slice(&chunk.data);
625-
}
626-
Ok(None) => {
627-
trace!("No chunk available. Retrying...\n");
628-
thread::sleep(Duration::from_millis(100));
629-
}
630-
Err(e) => {
631-
trace!("Failed to receive converted voice. ❌\n");
632-
test_result.push_str(&format!("4. Test receive converted voice ❌\n"));
633-
test_result.push_str(&format!("ERROR : {:?}\n", e));
634-
test_result.push_str(&format!("{test_name} ❌\n"));
635-
}
636-
}
637-
attempts += 1;
638-
}
639-
640-
test_result.push_str("4. Test receive converted voice ✅\n");
641-
642-
trace!("Saving converted audio data.");
643-
if !converted_audio_data.is_empty() {
644-
let dir = "/test-audio-files";
645-
let name = "test9-voice-conversion.mp3";
646-
save_audio(&converted_audio_data, dir, name);
647-
trace!("Audio saved at {dir}/{name} 💾\n");
648-
test_result.push_str(&format!("Audio saved at {dir}/{name} 💾\n"));
649-
650-
}
651-
652-
trace!("Closing stream...\n");
653-
stream.close();
654-
trace!("Stream closed successfully. ✅\n",);
655-
test_result.push_str("5. Test close stream ✅\n");
656-
test_result.push_str(&format!("{test_name} ✅\n"));
657-
658-
test_result
659-
}
660-
661381
// Test advanced voice operation
662382
// 1. Create voice clone
663383
// 2. Design voice
664384
// 3. Voice to voice
665385
// 4. Generate sound effects
666-
fn test10() -> String {
386+
fn test6() -> String {
667387
let voice = match get_voice(VOICE_UUID) {
668388
Ok(voices) => voices,
669389
Err(err) => {
@@ -796,7 +516,7 @@ impl Guest for Component {
796516
}
797517

798518
// Text long for synthesis
799-
fn test11() -> String {
519+
fn test7() -> String {
800520
let voice = match get_voice(VOICE_UUID) {
801521
Ok(voices) => voices,
802522
Err(err) => {
@@ -921,7 +641,7 @@ impl Guest for Component {
921641
}
922642

923643
// Test pronunciation lexicons
924-
fn test12() -> String {
644+
fn test8() -> String {
925645
let voice = match get_voice(VOICE_UUID) {
926646
Ok(voices) => voices,
927647
Err(err) => {

test/tts/components-rust/test-tts/wit/test-tts.wit

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,21 @@ package test:tts;
33
// See https://component-model.bytecodealliance.org/design/wit.html for more details about the WIT syntax
44

55
interface test-tts-api {
6+
test1: func() -> string;
67
test2: func() -> string;
8+
test3: func() -> string;
79
test4: func() -> string;
810
test5: func() -> string;
911
test6: func() -> string;
1012
test7: func() -> string;
1113
test8: func() -> string;
12-
test9: func() -> string;
13-
test10: func() -> string;
14-
test11: func() -> string;
15-
test12: func() -> string;
14+
1615
}
1716

1817
world test-tts {
1918
import golem:tts/types@1.0.0;
2019
import golem:tts/voices@1.0.0;
2120
import golem:tts/synthesis@1.0.0;
22-
import golem:tts/streaming@1.0.0;
2321
import golem:tts/advanced@1.0.0;
2422
export test-tts-api;
2523
}

0 commit comments

Comments
 (0)