Skip to content

Commit 129f80e

Browse files
committed
✨ feat: add speak fns
1 parent c939b91 commit 129f80e

File tree

7 files changed

+3516
-2806
lines changed

7 files changed

+3516
-2806
lines changed

packages/browser/speak/index.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
category: '@Browser'
3+
---
4+
5+
# speak
6+
7+
speaks a message.
8+
9+
## Usage
10+
11+
```ts
12+
import { speak } from '@use-kit/functions'
13+
14+
speak('Hi!')
15+
```

packages/browser/speak/index.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
export const speak = (
2+
text: string,
3+
lang = 'en-US',
4+
rate = 1.0,
5+
pitch = 1.0,
6+
volume = 1.0) => {
7+
if (typeof window !== 'undefined' && 'speechSynthesis' in window) {
8+
try {
9+
const utterance = new SpeechSynthesisUtterance(text)
10+
utterance.lang = lang
11+
utterance.rate = rate
12+
utterance.pitch = pitch
13+
utterance.volume = volume
14+
window.speechSynthesis.speak(utterance)
15+
return true
16+
}
17+
catch (error) {
18+
return false
19+
}
20+
}
21+
else {
22+
console.warn('Speech synthesis is not supported in this environment.')
23+
return false
24+
}
25+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
category: '@Browser'
3+
---
4+
5+
# speak
6+
7+
speaks a message.
8+
9+
## Usage
10+
11+
```ts
12+
import { speak } from '@use-kit/functions'
13+
14+
speak('Hi!')
15+
```
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
---
2+
category: '@Core'
3+
---
4+
5+
# cacheField
6+
7+
Cache a field value.
8+
9+
## Usage
10+
11+
<!-- ```ts
12+
import { cacheField } from '@vueuse/core'
13+
14+
const { value, set } = cacheField()
15+
set('foo', 'bar')
16+
value.value // 'bar'
17+
``` -->
18+
19+
```ts
20+
import { cacheField } from '@use-kit/functions'
21+
22+
const ret = await cacheField('a', 'test')
23+
```
Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,15 @@
1-
// TODO:
1+
---
2+
category: '@Core'
3+
---
4+
5+
# isValidJSON
6+
7+
Validates if a string is a valid JSON.
8+
9+
## Usage
10+
11+
```ts
12+
import { isValidJSON } from '@use-kit/functions'
13+
14+
isValidJSON('{ "foo": "bar" }') // true
15+
```
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,22 @@
11
// TODO:
2+
---
3+
category: '@Core'
4+
---
5+
6+
# stringByteSize
7+
8+
Checks if a string is of a certain length.
9+
10+
## Usage
11+
12+
```ts
13+
import { stringByteSize } from '@use-kit/functions'
14+
15+
stringByteSize('') // 0
16+
stringByteSize('a') // 1
17+
stringByteSize('ab') // 2
18+
stringByteSize('abc') // 3
19+
stringByteSize('abcd') // 4
20+
stringByteSize('abcde') // 5
21+
stringByteSize('😜') // 4
22+
```

0 commit comments

Comments
 (0)