-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
642510d
commit 770fdd3
Showing
4 changed files
with
60 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<script lang="ts" context="module"> | ||
import { writable } from 'svelte/store'; | ||
export let HREF = writable("") | ||
let FILENAME = writable("") | ||
export const convert_to_txt = function(sub_array) { | ||
/** | ||
* Convert Whisper Output to WebVTT | ||
* param sub_array: The Subtitles whisper returned | ||
*/ | ||
let result = ''; | ||
sub_array.forEach((elem) => { | ||
result += `${elem}\n` | ||
}) | ||
download('download.txt', result) | ||
return result | ||
} | ||
function download(filename, text) { | ||
HREF.set(`data:text/plain;charset=utf-8,${encodeURIComponent(text)}`) | ||
FILENAME.set(filename); | ||
} | ||
</script> | ||
|
||
<script lang="ts"> | ||
let file_contents = "" | ||
let filename = "" | ||
$: $HREF, file_contents = $HREF | ||
$: $FILENAME, filename = $FILENAME | ||
</script> | ||
|
||
<a href={file_contents} download={filename}><button class="btn btn-success"> | ||
Download TXT | ||
</button></a> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import {describe, test, expect, vi } from 'vitest'; | ||
import { convert_to_txt } from './TXT.svelte'; | ||
import {subs, TXT_OUTPUT} from './test_data'; | ||
|
||
describe("WebVTT Component", () => { | ||
test("It should generate a TXT file", () => { | ||
const result = convert_to_txt(subs) | ||
expect(result).equal(TXT_OUTPUT); | ||
}) | ||
}); |