Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e4af5b6

Browse files
♻️ refactor: Update dumi
1 parent c4fec41 commit e4af5b6

File tree

30 files changed

+315
-116
lines changed

30 files changed

+315
-116
lines changed

.dumirc.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,7 @@ export default defineConfig({
5252
'process.env': process.env,
5353
},
5454
favicons: ['https://lobehub.com/favicon.ico'],
55-
locales: [
56-
{ id: 'en-US', name: 'English' },
57-
{ id: 'zh-CN', name: '简体中文' },
58-
],
55+
locales: [{ id: 'en-US', name: 'English' }],
5956
// mfsu: isWin ? undefined : {},
6057
mfsu: false,
6158
npmClient: 'pnpm',

api/edge-speech.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
1-
import { EdgeSpeechPayload, createEdgeSpeech } from '../src/core/EdgeSpeechTTS/createEdgeSpeech';
1+
import cors from '../lib/cors';
2+
import { EdgeSpeechPayload, EdgeSpeechTTS } from '../src/core';
23

34
export const config = {
45
runtime: 'edge',
56
};
67

78
export default async (req: Request) => {
89
if (req.method !== 'POST') return new Response('Method Not Allowed', { status: 405 });
9-
1010
const payload = (await req.json()) as EdgeSpeechPayload;
1111

12-
return createEdgeSpeech({ payload });
12+
const res = await EdgeSpeechTTS.createRequest({ payload });
13+
14+
return cors(req, res);
1315
};

api/microsoft-speech.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
import {
2-
MicrosoftSpeechPayload,
3-
createMicrosoftSpeech,
4-
} from '../src/core/MicrosoftSpeechTTS/createMicrosoftSpeech';
1+
import cors from '../lib/cors';
2+
import { MicrosoftSpeechPayload, MicrosoftSpeechTTS } from '../src/core';
53

64
export const config = {
75
runtime: 'edge',
@@ -11,5 +9,7 @@ export default async (req: Request) => {
119
if (req.method !== 'POST') return new Response('Method Not Allowed', { status: 405 });
1210
const payload = (await req.json()) as MicrosoftSpeechPayload;
1311

14-
return createMicrosoftSpeech({ payload });
12+
const res = await MicrosoftSpeechTTS.createRequest({ payload });
13+
14+
return cors(req, res);
1515
};

api/openai-stt.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import OpenAI from 'openai';
22

33
import { OpenAISTTPayload } from '@/core';
44

5+
import cors from '../lib/cors';
56
import { createOpenaiAudioTranscriptions } from '../src/server/createOpenaiAudioTranscriptions';
67

78
export const config = {
@@ -21,9 +22,12 @@ export default async (req: Request) => {
2122
const openai = new OpenAI({ apiKey: OPENAI_API_KEY, baseURL: OPENAI_BASE_URL });
2223
const res = await createOpenaiAudioTranscriptions({ openai, payload });
2324

24-
return new Response(JSON.stringify(res), {
25-
headers: {
26-
'content-type': 'application/json;charset=UTF-8',
27-
},
28-
});
25+
return cors(
26+
req,
27+
new Response(JSON.stringify(res), {
28+
headers: {
29+
'content-type': 'application/json;charset=UTF-8',
30+
},
31+
}),
32+
);
2933
};

api/openai-tts.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import OpenAI from 'openai';
22

33
import { OpenAITTSPayload } from '@/core';
44

5+
import cors from '../lib/cors';
56
import { createOpenaiAudioSpeech } from '../src/server/createOpenaiAudioSpeech';
67

78
export const config = {
@@ -10,6 +11,7 @@ export const config = {
1011

1112
export default async (req: Request) => {
1213
if (req.method !== 'POST') return new Response('Method Not Allowed', { status: 405 });
14+
1315
const OPENAI_API_KEY = process.env.OPENAI_API_KEY;
1416
const OPENAI_BASE_URL = process.env.OPENAI_BASE_URL;
1517

@@ -19,5 +21,7 @@ export default async (req: Request) => {
1921

2022
const openai = new OpenAI({ apiKey: OPENAI_API_KEY, baseURL: OPENAI_BASE_URL });
2123

22-
return createOpenaiAudioSpeech({ openai, payload });
24+
const res = await createOpenaiAudioSpeech({ openai, payload });
25+
26+
return cors(req, res);
2327
};

docs/STT.tsx

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { Icon } from '@lobehub/ui';
2+
import { Button, Input } from 'antd';
3+
import { Mic, StopCircle } from 'lucide-react';
4+
import { Flexbox } from 'react-layout-kit';
5+
6+
import { useSpeechRecognition } from '@/react';
7+
8+
export default () => {
9+
const { text, start, stop, isLoading, formattedTime, url } = useSpeechRecognition('zh-CN');
10+
return (
11+
<Flexbox gap={8}>
12+
{isLoading ? (
13+
<Button block icon={<Icon icon={StopCircle} />} onClick={stop}>
14+
Stop {formattedTime}
15+
</Button>
16+
) : (
17+
<Button block icon={<Icon icon={Mic} />} onClick={start} type={'primary'}>
18+
Recognition
19+
</Button>
20+
)}
21+
<Input.TextArea placeholder={'Recognition result...'} value={text} />
22+
{url && <audio controls src={url} />}
23+
</Flexbox>
24+
);
25+
};

docs/TTS.tsx

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { Icon } from '@lobehub/ui';
2+
import { Button, Input } from 'antd';
3+
import { Volume2 } from 'lucide-react';
4+
import { Flexbox } from 'react-layout-kit';
5+
6+
import { AudioPlayer, useEdgeSpeech } from '@/react';
7+
8+
export default () => {
9+
const { setText, isGlobalLoading, start, stop, audio } = useEdgeSpeech('Edge Speech Example', {
10+
api: {},
11+
options: {
12+
voice: 'zh-CN-YunxiaNeural',
13+
},
14+
});
15+
16+
return (
17+
<Flexbox gap={8}>
18+
{isGlobalLoading ? (
19+
<Button block loading onClick={stop}>
20+
Generating...
21+
</Button>
22+
) : (
23+
<Button block icon={<Icon icon={Volume2} />} onClick={start} type={'primary'}>
24+
Speak
25+
</Button>
26+
)}
27+
<Input.TextArea
28+
defaultValue={'Edge Speech Example'}
29+
onChange={(e) => setText(e.target.value)}
30+
/>
31+
<AudioPlayer audio={audio} isLoading={isGlobalLoading} onLoadingStop={stop} />
32+
</Flexbox>
33+
);
34+
};

docs/api-reference/edge-speech-tts.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
---
2-
group: TTS
2+
group: API Reference
33
title: EdgeSpeechTTS
44
apiHeader:
55
pkg: '@lobehub/tts'
66
---
77

8+
## Introduction
9+
810
`EdgeSpeechTTS` is a class for text-to-speech conversion based on Edge Speech Service.
911

1012
This class supports converting text to speech and provides a set of methods to retrieve voice options and create speech synthesis requests.

docs/api-reference/edge-speech-tts.zh-CN.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
---
2-
group: TTS
2+
group: API Reference
33
title: EdgeSpeechTTS
44
apiHeader:
55
pkg: '@lobehub/tts'
66
---
77

8+
## 介绍
9+
810
`EdgeSpeechTTS` 是一个基于 Edge 语音服务的文本转语音方法类。
911

1012
该类支持将文本转换为语音,并提供了一系列方法来获取语音选项,创建语音合成请求。

docs/api-reference/index.md

Lines changed: 0 additions & 14 deletions
This file was deleted.

0 commit comments

Comments
 (0)