1
1
import { expect , test } from 'vitest' ;
2
2
3
- test ( 'speech -to-text ' , async ( ) => {
3
+ test ( 'text -to-speech ' , async ( ) => {
4
4
return new Promise ( async ( resolve ) => {
5
- const { transcribeAudioFile } = await import ( "../src/index" ) ;
5
+ const { textToSpeech } = await import ( "../src/index" ) ;
6
+
7
+ const audio = await textToSpeech ( "Hello, World!" ) ;
8
+ expect ( audio ) . toBeDefined ( ) ;
6
9
7
- const input = document . createElement ( "button" ) ;
10
+ resolve ( true ) ;
11
+ } ) ;
12
+ } ) ;
8
13
9
- input . onclick = async ( e ) => {
10
- const response = await fetch ( "https://huggingface.co/datasets/Xenova/transformers.js-docs/ resolve/main/ted_60_16k.wav" ) ;
11
- const blob = await response . blob ( ) ;
14
+ test ( 'speech-to-text' , async ( ) => {
15
+ return new Promise ( async ( resolve ) => {
16
+ const { transcribeAudioFile } = await import ( "../src/index" ) ;
12
17
13
- const text = await transcribeAudioFile ( blob ) ;
14
- console . log ( text ) ;
15
- expect ( text ) . toBeDefined ( ) ;
18
+ const response = await fetch ( "https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/ted_60_16k.wav" ) ;
19
+ const blob = await response . blob ( ) ;
16
20
17
- resolve ( true ) ;
18
- } ;
21
+ const text = await transcribeAudioFile ( blob ) ;
22
+ expect ( text ) . toBeDefined ( ) ;
19
23
20
- document . body . appendChild ( input ) ;
24
+ resolve ( true ) ;
21
25
} ) ;
22
26
} ) ;
23
27
24
28
test ( 'ocr' , async ( ) => {
25
29
return new Promise ( async ( resolve ) => {
26
30
const { ocr } = await import ( "../src/index" ) ;
27
31
28
- const input = document . createElement ( "input" ) ;
29
- input . type = "file" ;
30
- input . accept = "image/*" ;
32
+ const response = await fetch ( "https://picsum.photos/200/300" ) ;
33
+ const blob = await response . blob ( ) ;
34
+
35
+ const text = await ocr ( blob ) ;
36
+
37
+ expect ( text ) . toBeDefined ( ) ;
38
+ resolve ( true ) ;
39
+ } ) ;
40
+ } ) ;
41
+
42
+ test ( 'image-classification' , async ( ) => {
43
+ return new Promise ( async ( resolve ) => {
44
+ const { classifyImage } = await import ( "../src/index" ) ;
45
+
46
+ const response = await fetch ( "https://picsum.photos/200/300" ) ;
47
+ const blob = await response . blob ( ) ;
31
48
32
- input . onchange = async ( e ) => {
33
- const file = ( e . target as any ) . files [ 0 ] ;
34
- const text = await ocr ( URL . createObjectURL ( file ) as any ) ;
49
+ const text = await classifyImage ( blob ) ;
50
+
51
+ expect ( text ) . toBeDefined ( ) ;
52
+ resolve ( true ) ;
53
+ } ) ;
54
+ } ) ;
55
+
56
+ test ( 'summarize' , async ( ) => {
57
+ return new Promise ( async ( resolve ) => {
58
+ const { summarize } = await import ( "../src/index" ) ;
35
59
36
- expect ( text ) . toBeDefined ( ) ;
37
- resolve ( true ) ;
38
- } ;
60
+ const text = "the red fox is a small fox that lives in the forest. it has a red coat and a bushy tail. the red fox is a carnivore, which means it eats meat. it hunts small animals like rabbits" ;
61
+ const summary = await summarize ( text ) ;
39
62
40
- document . body . appendChild ( input ) ;
63
+ expect ( summary ) . toBeDefined ( ) ;
64
+ resolve ( true ) ;
41
65
} ) ;
42
66
} ) ;
0 commit comments