Skip to content

Commit

Permalink
♻️ refactor: 将react 部分抽取到 /react 子级路径下
Browse files Browse the repository at this point in the history
  • Loading branch information
semantic-release-bot authored and 闻冰 committed Nov 15, 2023
1 parent 26a4ad7 commit 80b24e8
Show file tree
Hide file tree
Showing 48 changed files with 83 additions and 77 deletions.
9 changes: 4 additions & 5 deletions .dumirc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,10 @@ export default defineConfig({
mfsu: isWin ? undefined : {},
npmClient: 'pnpm',
publicPath: '/',
resolve: isProduction
? {
entryFile: './src/index.ts',
}
: undefined,
resolve: {
atomDirs: [{ dir: 'src/react', type: 'component' }],
entryFile: isProduction ? './src/index.ts' : undefined,
},
styles: [
`html, body { background: transparent; }
Expand Down
13 changes: 13 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,19 @@
"license": "MIT",
"author": "LobeHub <[email protected]>",
"sideEffects": false,
"exports": {
"./package.json": "./package.json",
".": {
"types": "./es/index.d.ts",
"import": "./es/index.js",
"module": "./es/index.js"
},
"./react": {
"types": "./es/react/index.d.ts",
"import": "./es/react/index.js",
"module": "./es/react/index.js"
}
},
"main": "es/index.js",
"module": "es/index.js",
"types": "es/index.d.ts",
Expand Down
29 changes: 5 additions & 24 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,36 +1,12 @@
export { default as AudioPlayer, type AudioPlayerProps } from './AudioPlayer';
export { default as AudioVisualizer, type AudioVisualizerProps } from './AudioVisualizer';
export { default as azureVoiceList } from './data/azureVoiceList';
export { default as edgeVoiceList } from './data/edgeVoiceList';
export { default as voiceLocale } from './data/locales';
export { default as openaiVoiceList } from './data/openaiVoiceList';
export { default as voiceList } from './data/voiceList';
export { useAudioPlayer } from './hooks/useAudioPlayer';
export { useAudioVisualizer } from './hooks/useAudioVisualizer';
export { useBlobUrl } from './hooks/useBlobUrl';
export { useStreamAudioPlayer } from './hooks/useStreamAudioPlayer';
export { type EdgeSpeechOptions, fetchEdgeSpeech } from './services/fetchEdgeSpeech';
export { fetchMicrosoftSpeech, type MicrosoftSpeechOptions } from './services/fetchMicrosoftSpeech';
export { fetchOpenaiSTT, type OpenaiSttOptions } from './services/fetchOpenaiSTT';
export { fetchOpenaiTTS, type OpenaiTtsOptions } from './services/fetchOpenaiTTS';
export { useAudioRecorder } from './useAudioRecorder';
export { useEdgeSpeech } from './useEdgeSpeech';
export { useMicrosoftSpeech } from './useMicrosoftSpeech';
export {
type OpenaiSpeechRecognitionOptions,
type OpenaiSTTFetcher,
useOpenaiSTT,
useOpenaiSTTWithPSR,
useOpenaiSTTWithRecord,
useOpenaiSTTWithSR,
} from './useOpenaiSTT';
export { useOpenaiTTS } from './useOpenaiTTS';
export { usePersistedSpeechRecognition } from './useSpeechRecognition/usePersistedSpeechRecognition';
export {
type SpeechRecognitionOptions,
useSpeechRecognition,
} from './useSpeechRecognition/useSpeechRecognition';
export { useSpeechSynthes } from './useSpeechSynthes';
export { getRecordMineType, type RecordMineType } from './utils/getRecordMineType';
export {
genLevaOptions,
Expand All @@ -46,3 +22,8 @@ export {
OPENAI_STT_API_URL,
OPENAI_TTS_API_URL,
} from '@/const/api';
export { createEdgeSpeechComletion } from '@/server/createEdgeSpeechComletion';
export { createMicrosoftSpeechComletion } from '@/server/createMicrosoftSpeechComletion';
export { createOpenaiAudioSpeechCompletion } from '@/server/createOpenaiAudioSpeechCompletion';
export { createOpenaiAudioTranscriptionsCompletion } from '@/server/createOpenaiAudioTranscriptionsCompletion';
export * from '@/server/types';
24 changes: 24 additions & 0 deletions src/react.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
export { default as AudioPlayer, type AudioPlayerProps } from '@/react/AudioPlayer';
export { default as AudioVisualizer, type AudioVisualizerProps } from '@/react/AudioVisualizer';
export { useAudioPlayer } from '@/react/hooks/useAudioPlayer';
export { useAudioVisualizer } from '@/react/hooks/useAudioVisualizer';
export { useBlobUrl } from '@/react/hooks/useBlobUrl';
export { useStreamAudioPlayer } from '@/react/hooks/useStreamAudioPlayer';
export { useAudioRecorder } from '@/react/useAudioRecorder';
export { useEdgeSpeech } from '@/react/useEdgeSpeech';
export { useMicrosoftSpeech } from '@/react/useMicrosoftSpeech';
export {
type OpenaiSpeechRecognitionOptions,
type OpenaiSTTFetcher,
useOpenaiSTT,
useOpenaiSTTWithPSR,
useOpenaiSTTWithRecord,
useOpenaiSTTWithSR,
} from '@/react/useOpenaiSTT';
export { useOpenaiTTS } from '@/react/useOpenaiTTS';
export { usePersistedSpeechRecognition } from '@/react/useSpeechRecognition/usePersistedSpeechRecognition';
export {
type SpeechRecognitionOptions,
useSpeechRecognition,
} from '@/react/useSpeechRecognition/useSpeechRecognition';
export { useSpeechSynthes } from '@/react/useSpeechSynthes';
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AudioPlayer, useAudioPlayer } from '@lobehub/tts';
import { AudioPlayer, useAudioPlayer } from '@lobehub/tts/react';
import { StoryBook, useControls, useCreateStore } from '@lobehub/ui';

export default () => {
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { useAudioVisualizer } from '@lobehub/tts';
import { useTheme } from 'antd-style';
import { RefObject, memo } from 'react';

import { useAudioVisualizer } from '../hooks/useAudioVisualizer';

export interface VisualizerProps {
borderRadius?: number;
color?: string;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AudioPlayer, AudioVisualizer, useAudioPlayer } from '@lobehub/tts';
import { AudioPlayer, AudioVisualizer, useAudioPlayer } from '@lobehub/tts/react';
import { StoryBook, useControls, useCreateStore } from '@lobehub/ui';
import { Flexbox } from 'react-layout-kit';

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { CSSProperties, RefObject, memo } from 'react';
import { ErrorBoundary } from 'react-error-boundary';
import { Flexbox } from 'react-layout-kit';

import Visualizer, { VisualizerProps } from '@/AudioVisualizer/Visualizer';
import Visualizer, { VisualizerProps } from '@/react/AudioVisualizer/Visualizer';

export interface AudioVisualizerProps {
audioRef: RefObject<HTMLAudioElement>;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { RefObject, useCallback, useEffect, useRef, useState } from 'react';
import useSWR from 'swr';

import { AudioProps } from '@/AudioPlayer';
import { AudioProps } from '@/react/AudioPlayer';
import { arrayBufferConvert } from '@/utils/arrayBufferConvert';
import { audioBufferToBlob } from '@/utils/audioBufferToBlob';

Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { RefObject, useCallback, useEffect, useRef, useState } from 'react';

import { AudioProps } from '@/AudioPlayer';
import { AudioProps } from '@/react/AudioPlayer';
import { audioBufferToBlob, audioBuffersToBlob } from '@/utils/audioBufferToBlob';

export interface StreamAudioPlayerHook extends AudioProps {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useAudioRecorder } from '@lobehub/tts';
import { useAudioRecorder } from '@lobehub/tts/react';
import { Icon } from '@lobehub/ui';
import { Button } from 'antd';
import { Mic, StopCircle } from 'lucide-react';
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
import {
AudioPlayer,
EDGE_SPEECH_API_URL,
genLevaOptions,
getEdgeVoiceOptions,
useEdgeSpeech,
} from '@lobehub/tts';
import { EDGE_SPEECH_API_URL, genLevaOptions, getEdgeVoiceOptions } from '@lobehub/tts';
import { AudioPlayer, useEdgeSpeech } from '@lobehub/tts/react';
import { Icon, StoryBook, useControls, useCreateStore } from '@lobehub/ui';
import { Button, Input } from 'antd';
import { Volume2 } from 'lucide-react';
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useState } from 'react';

import { useTTS } from '@/react/useTTS';
import { EdgeSpeechOptions, fetchEdgeSpeech } from '@/services/fetchEdgeSpeech';
import { useTTS } from '@/useTTS';

export const useEdgeSpeech = (defaultText: string, options: EdgeSpeechOptions) => {
const [text, setText] = useState<string>(defaultText);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
import {
AudioPlayer,
MICROSOFT_SPEECH_API_URL,
genLevaOptions,
getEdgeVoiceOptions,
useMicrosoftSpeech,
} from '@lobehub/tts';
import { MICROSOFT_SPEECH_API_URL, genLevaOptions, getEdgeVoiceOptions } from '@lobehub/tts';
import { AudioPlayer, useMicrosoftSpeech } from '@lobehub/tts/react';
import { Icon, StoryBook, useControls, useCreateStore } from '@lobehub/ui';
import { Button, Input } from 'antd';
import { Volume2 } from 'lucide-react';
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useState } from 'react';

import { useTTS } from '@/react/useTTS';
import { type MicrosoftSpeechOptions, fetchMicrosoftSpeech } from '@/services/fetchMicrosoftSpeech';
import { useTTS } from '@/useTTS';

export const useMicrosoftSpeech = (defaultText: string, options: MicrosoftSpeechOptions) => {
const [text, setText] = useState<string>(defaultText);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useOpenaiSTTWithPSR } from '@lobehub/tts';
import { useOpenaiSTTWithPSR } from '@lobehub/tts/react';
import { Icon, StoryBook, useControls, useCreateStore } from '@lobehub/ui';
import { Button, Input } from 'antd';
import { Mic, StopCircle } from 'lucide-react';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useOpenaiSTTWithSR } from '@lobehub/tts';
import { useOpenaiSTTWithSR } from '@lobehub/tts/react';
import { Icon, StoryBook, useControls, useCreateStore } from '@lobehub/ui';
import { Button, Input } from 'antd';
import { Mic, StopCircle } from 'lucide-react';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { OPENAI_STT_API_URL, useOpenaiSTTWithRecord } from '@lobehub/tts';
import { OPENAI_STT_API_URL } from '@lobehub/tts';
import { useOpenaiSTTWithRecord } from '@lobehub/tts/react';
import { Icon, StoryBook, useControls, useCreateStore } from '@lobehub/ui';
import { Button, Input } from 'antd';
import { Mic, StopCircle } from 'lucide-react';
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useCallback, useState } from 'react';

import { OpenaiSTTFetcher, useOpenaiSTT } from '@/useOpenaiSTT/useOpenaiSTT';
import { usePersistedSpeechRecognition } from '@/useSpeechRecognition';
import { OpenaiSTTFetcher, useOpenaiSTT } from '@/react/useOpenaiSTT/useOpenaiSTT';
import { usePersistedSpeechRecognition } from '@/react/useSpeechRecognition';

import { OpenaiSpeechRecognitionOptions } from './useOpenaiSTTWithRecord';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { useCallback, useState } from 'react';

import { useAudioRecorder } from '@/react/useAudioRecorder';
import { OpenaiSTTFetcher, useOpenaiSTT } from '@/react/useOpenaiSTT/useOpenaiSTT';
import { SpeechRecognitionOptions } from '@/react/useSpeechRecognition/useSpeechRecognition';
import { OpenaiSttOptions } from '@/services/fetchOpenaiSTT';
import { useAudioRecorder } from '@/useAudioRecorder';
import { OpenaiSTTFetcher, useOpenaiSTT } from '@/useOpenaiSTT/useOpenaiSTT';
import { SpeechRecognitionOptions } from '@/useSpeechRecognition/useSpeechRecognition';

export type OpenaiSpeechRecognitionOptions = SpeechRecognitionOptions & OpenaiSttOptions;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useCallback, useState } from 'react';

import { OpenaiSTTFetcher, useOpenaiSTT } from '@/useOpenaiSTT/useOpenaiSTT';
import { useSpeechRecognition } from '@/useSpeechRecognition';
import { OpenaiSTTFetcher, useOpenaiSTT } from '@/react/useOpenaiSTT/useOpenaiSTT';
import { useSpeechRecognition } from '@/react/useSpeechRecognition';

import { OpenaiSpeechRecognitionOptions } from './useOpenaiSTTWithRecord';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { AudioPlayer, OPENAI_TTS_API_URL, openaiVoiceList, useOpenaiTTS } from '@lobehub/tts';
import { OPENAI_TTS_API_URL, openaiVoiceList } from '@lobehub/tts';
import { AudioPlayer, useOpenaiTTS } from '@lobehub/tts/react';
import { Icon, StoryBook, useControls, useCreateStore } from '@lobehub/ui';
import { Button, Input } from 'antd';
import { Volume2 } from 'lucide-react';
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useState } from 'react';

import { useTTS } from '@/react/useTTS';
import { type OpenaiTtsOptions, fetchOpenaiTTS } from '@/services/fetchOpenaiTTS';
import { useTTS } from '@/useTTS';

export const useOpenaiTTS = (defaultText: string, options: OpenaiTtsOptions) => {
const [text, setText] = useState<string>(defaultText);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { usePersistedSpeechRecognition } from '@lobehub/tts';
import { usePersistedSpeechRecognition } from '@lobehub/tts/react';
import { Icon, StoryBook, useControls, useCreateStore } from '@lobehub/ui';
import { Button, Input } from 'antd';
import { Mic, StopCircle } from 'lucide-react';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useSpeechRecognition } from '@lobehub/tts';
import { useSpeechRecognition } from '@lobehub/tts/react';
import { Icon, StoryBook, useControls, useCreateStore } from '@lobehub/ui';
import { Button, Input } from 'antd';
import { Mic, StopCircle } from 'lucide-react';
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useCallback, useMemo, useState } from 'react';

import { useAudioRecorder } from '@/useAudioRecorder';
import { useAudioRecorder } from '@/react/useAudioRecorder';

import { useRecognition } from './useRecognition';
import { SpeechRecognitionOptions } from './useSpeechRecognition';
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useCallback } from 'react';

import { useAudioRecorder } from '@/useAudioRecorder';
import { useRecognition } from '@/useSpeechRecognition/useRecognition';
import { useAudioRecorder } from '@/react/useAudioRecorder';
import { useRecognition } from '@/react/useSpeechRecognition/useRecognition';

export interface SpeechRecognitionOptions {
onBolbAvailable?: (blob: Blob) => void;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { genLevaOptions, getSpeechSynthesVoiceOptions, useSpeechSynthes } from '@lobehub/tts';
import { genLevaOptions, getSpeechSynthesVoiceOptions } from '@lobehub/tts';
import { useSpeechSynthes } from '@lobehub/tts/react';
import { Icon, StoryBook, useControls, useCreateStore } from '@lobehub/ui';
import { Button, Input } from 'antd';
import { StopCircle, Volume2 } from 'lucide-react';
Expand Down
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions src/useTTS/index.ts → src/react/useTTS/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { useCallback, useEffect, useState } from 'react';
import useSWR from 'swr';

import { AudioProps } from '@/AudioPlayer';
import { useStreamAudioPlayer } from '@/hooks/useStreamAudioPlayer';
import { AudioProps } from '@/react/AudioPlayer';
import { useStreamAudioPlayer } from '@/react/hooks/useStreamAudioPlayer';
import { splitTextIntoSegments } from '@/utils/splitTextIntoSegments';

export interface TTSHook {
Expand Down
5 changes: 0 additions & 5 deletions src/server.ts

This file was deleted.

0 comments on commit 80b24e8

Please sign in to comment.