-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from liuhuapiaoyuan/feature/voice-provider
Feature/voice provider
- Loading branch information
Showing
10 changed files
with
235 additions
and
31 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,3 +7,4 @@ htmlcov | |
.cache | ||
.venv | ||
.env | ||
tmp/cache/* |
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 |
---|---|---|
@@ -0,0 +1,33 @@ | ||
from fish_audio_sdk import Session, TTSRequest, ReferenceAudio | ||
from pydub import AudioSegment | ||
import io | ||
|
||
from constants import FISHAUDIO_KEY,FISHAUDIO_SPEEKER | ||
|
||
|
||
|
||
import random | ||
|
||
def get_adapter_speeker_id(speaker_name): | ||
speeker = FISHAUDIO_SPEEKER[0] | ||
if speaker_name != "主持人": | ||
speeker = random.choice(FISHAUDIO_SPEEKER) | ||
return speeker["id"] | ||
|
||
def fishaudio_tts(text, reference_id=None) -> AudioSegment: | ||
""" | ||
将给定的文本转换为语音并返回AudioSegment对象。 | ||
:param text: 要转换的文本 | ||
:param reference_id: 可选参数,使用的模型 ID | ||
:return: 返回生成的语音的AudioSegment对象 | ||
""" | ||
session = Session(FISHAUDIO_KEY) | ||
audio_buffer = io.BytesIO() | ||
for chunk in session.tts(TTSRequest( | ||
reference_id=reference_id, | ||
text=text | ||
)): | ||
audio_buffer.write(chunk) | ||
audio_buffer.seek(0) # 重置缓冲区的位置 | ||
return AudioSegment.from_file(audio_buffer, format="mp3") |
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 |
---|---|---|
|
@@ -18,3 +18,4 @@ numpy==2.1.1 | |
python-multipart==0.0.12 | ||
PyPDF2==3.0.1 | ||
azure-cognitiveservices-speech==1.41.1 | ||
fish_audio_sdk |
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
Oops, something went wrong.