-
-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
♻️ refactor: refactor to class usage and ui
- Loading branch information
Showing
80 changed files
with
549 additions
and
552 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
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 |
---|---|---|
|
@@ -55,5 +55,7 @@ next-env.d.ts | |
.env | ||
public/*.js | ||
bun.lockb | ||
react | ||
server | ||
react/** | ||
server/** | ||
|
||
core/** |
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
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
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
File renamed without changes.
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,57 @@ | ||
import edgeVoiceList from '@/core/EdgeSpeechTTS/edgeVoiceList'; | ||
import voiceName from '@/core/data/voiceList'; | ||
import { arrayBufferConvert } from '@/core/utils/arrayBufferConvert'; | ||
import { SsmlOptions } from '@/core/utils/genSSML'; | ||
import { getVoiceLocaleOptions } from '@/core/utils/getVoiceList'; | ||
|
||
import { createEdgeSpeech } from './createEdgeSpeech'; | ||
import { getEdgeVoiceOptions } from './options'; | ||
|
||
export interface EdgeSpeechPayload { | ||
/** | ||
* @title 语音合成的文本 | ||
*/ | ||
input: string; | ||
/** | ||
* @title SSML 语音合成的配置 | ||
*/ | ||
options: Pick<SsmlOptions, 'voice'>; | ||
} | ||
|
||
export class EdgeSpeechTTS { | ||
private locale?: string; | ||
private BASE_URL: string | undefined; | ||
|
||
constructor({ baseURL, locale }: { baseURL?: string; locale?: string } = {}) { | ||
this.locale = locale; | ||
this.BASE_URL = baseURL; | ||
} | ||
|
||
get voiceOptions() { | ||
return getEdgeVoiceOptions(this.locale); | ||
} | ||
|
||
static localeOptions = getVoiceLocaleOptions(); | ||
static voiceList = edgeVoiceList; | ||
static voiceName = voiceName; | ||
static completion = createEdgeSpeech; | ||
|
||
private fetch = async (payload: EdgeSpeechPayload) => { | ||
const response = await (this.BASE_URL | ||
? fetch(this.BASE_URL, { body: JSON.stringify(payload), method: 'POST' }) | ||
: createEdgeSpeech({ payload })); | ||
|
||
if (!response.ok) { | ||
throw new Error('Network response was not ok'); | ||
} | ||
return response; | ||
}; | ||
|
||
create = async (payload: EdgeSpeechPayload): Promise<AudioBuffer> => { | ||
const response = await this.fetch(payload); | ||
|
||
const arrayBuffer = await response.arrayBuffer(); | ||
|
||
return arrayBufferConvert(arrayBuffer); | ||
}; | ||
} |
Oops, something went wrong.