Skip to content

Commit a7a5d3d

Browse files
grorge123hydai
authored andcommitted
[Example] ChatTTS: remove write byte function
1 parent 044d45f commit a7a5d3d

File tree

3 files changed

+12
-7
lines changed

3 files changed

+12
-7
lines changed

wasmedge-chatTTS/README.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,5 +58,12 @@ let config_data = serde_json::to_string(&json!({"prompt": "[oral_2][laugh_0][bre
5858
.as_bytes()
5959
.to_vec();
6060
```
61+
<table>
62+
<tr>
63+
<td>
6164

62-
And it is the [Demo speaker](./assets/demo.wav).
65+
[demo.webm](https://github.com/user-attachments/assets/377e0487-9107-41db-9c22-31962ce53f88)
66+
67+
</td>
68+
</tr>
69+
</table>

wasmedge-chatTTS/assets/demo.webm

29.5 KB
Binary file not shown.

wasmedge-chatTTS/src/main.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ use wasmedge_wasi_nn::{
44
self, ExecutionTarget, GraphBuilder, GraphEncoding, GraphExecutionContext, TensorType,
55
};
66

7-
fn get_data_from_context(context: &GraphExecutionContext, index: usize, limit: usize) -> Vec<u8> {
7+
fn get_data_from_context(context: &GraphExecutionContext, index: usize) -> Vec<u8> {
88
const MAX_OUTPUT_BUFFER_SIZE: usize = 4096 * 4096;
99
let mut output_buffer = vec![0u8; MAX_OUTPUT_BUFFER_SIZE];
10-
let _ = context
10+
let bytes_written = context
1111
.get_output(index, &mut output_buffer)
1212
.expect("Failed to get output");
1313

14-
return output_buffer[..limit].to_vec();
14+
return output_buffer[..bytes_written].to_vec();
1515
}
1616

1717
fn main() {
@@ -35,9 +35,7 @@ fn main() {
3535
.set_input(1, TensorType::U8, &[1], &config_data)
3636
.expect("Failed to set input");
3737
context.compute().expect("Failed to compute");
38-
let bytes_written = get_data_from_context(&context, 1, 4);
39-
let bytes_written = usize::from_le_bytes(bytes_written.as_slice().try_into().unwrap());
40-
let output_bytes = get_data_from_context(&context, 0, bytes_written);
38+
let output_bytes = get_data_from_context(&context, 0);
4139
let spec = hound::WavSpec {
4240
channels: 1,
4341
sample_rate: 24000,

0 commit comments

Comments
 (0)