forked from 2noise/ChatTTS
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(webui): crash on non-ffmpeg env. (2noise#466)
- Loading branch information
Showing
5 changed files
with
27 additions
and
15 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
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 |
---|---|---|
@@ -1,2 +1 @@ | ||
from .np import unsafe_float_to_int16 | ||
from .av import wav2 | ||
from .mp3 import wav_arr_to_mp3_view |
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,20 @@ | ||
import wave | ||
from io import BytesIO | ||
|
||
import numpy as np | ||
|
||
from .np import unsafe_float_to_int16 | ||
from .av import wav2 | ||
|
||
def wav_arr_to_mp3_view(wav: np.ndarray): | ||
buf = BytesIO() | ||
with wave.open(buf, "wb") as wf: | ||
wf.setnchannels(1) # Mono channel | ||
wf.setsampwidth(2) # Sample width in bytes | ||
wf.setframerate(24000) # Sample rate in Hz | ||
wf.writeframes(unsafe_float_to_int16(wav)) | ||
buf.seek(0, 0) | ||
buf2 = BytesIO() | ||
wav2(buf, buf2, "mp3") | ||
buf.seek(0, 0) | ||
return buf2.getbuffer() |