Skip to content

Commit

Permalink
[Example] ChatTTS: remove write byte function
Browse files Browse the repository at this point in the history
  • Loading branch information
grorge123 committed Jul 29, 2024
1 parent c7acef1 commit c5c6364
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
9 changes: 8 additions & 1 deletion wasmedge-chatTTS/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,12 @@ let config_data = serde_json::to_string(&json!({"prompt": "[oral_2][laugh_0][bre
.as_bytes()
.to_vec();
```
<table>
<tr>
<td>

And it is the [Demo speaker](./assets/demo.wav).
[demo.webm](https://github.com/user-attachments/assets/377e0487-9107-41db-9c22-31962ce53f88)

</td>
</tr>
</table>
Binary file added wasmedge-chatTTS/assets/demo.webm
Binary file not shown.
10 changes: 4 additions & 6 deletions wasmedge-chatTTS/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ use wasmedge_wasi_nn::{
self, ExecutionTarget, GraphBuilder, GraphEncoding, GraphExecutionContext, TensorType,
};

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

return output_buffer[..limit].to_vec();
return output_buffer[..bytes_written].to_vec();
}

fn main() {
Expand All @@ -35,9 +35,7 @@ fn main() {
.set_input(1, TensorType::U8, &[1], &config_data)
.expect("Failed to set input");
context.compute().expect("Failed to compute");
let bytes_written = get_data_from_context(&context, 1, 4);
let bytes_written = usize::from_le_bytes(bytes_written.as_slice().try_into().unwrap());
let output_bytes = get_data_from_context(&context, 0, bytes_written);
let output_bytes = get_data_from_context(&context, 0);
let spec = hound::WavSpec {
channels: 1,
sample_rate: 24000,
Expand Down

0 comments on commit c5c6364

Please sign in to comment.