Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

调整语速 #90

Merged
merged 3 commits into from
Jan 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 7 additions & 4 deletions openaiapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from transformers import AutoTokenizer
import numpy as np
import soundfile as sf
import pyrubberband as pyrb
from pydub import AudioSegment
from yacs import config as CONFIG
from config.joint.config import Config
Expand Down Expand Up @@ -165,15 +166,17 @@ def text_to_speech(speechRequest: SpeechRequest):
np_audio = emotivoice_tts(text, speechRequest.prompt,
speechRequest.input, speechRequest.voice,
models)
y_stretch = np_audio
if speechRequest.speed != 1.0:
y_stretch = pyrb.time_stretch(np_audio, config.sampling_rate, speechRequest.speed)
wav_buffer = io.BytesIO()
sf.write(file=wav_buffer, data=np_audio,
sf.write(file=wav_buffer, data=y_stretch,
samplerate=config.sampling_rate, format='WAV')
buffer = wav_buffer
response_format = speechRequest.response_format
if response_format != 'wav':
wav_audio = AudioSegment(
wav_buffer.getvalue(), frame_rate=config.sampling_rate,
sample_width=2, channels=1)
wav_audio = AudioSegment.from_wav(wav_buffer)
wav_audio.frame_rate=config.sampling_rate
buffer = io.BytesIO()
wav_audio.export(buffer, format=response_format)

Expand Down
1 change: 1 addition & 0 deletions requirements.openaiapi.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ fastapi
python-multipart
uvicorn[standard]
pydub
pyrubberband