Skip to content

Commit

Permalink
chore(tools): rename wav_arr_to_mp3_view to pcm_arr_to_mp3_view
Browse files Browse the repository at this point in the history
  • Loading branch information
fumiama committed Jul 10, 2024
1 parent 580463c commit af8a4e3
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 7 deletions.
4 changes: 2 additions & 2 deletions examples/api/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

import ChatTTS

from tools.audio import wav_arr_to_mp3_view
from tools.audio import pcm_arr_to_mp3_view
from tools.logger import get_logger
import torch

Expand Down Expand Up @@ -101,7 +101,7 @@ async def generate_voice(params: ChatTTSParams):
buf, "a", compression=zipfile.ZIP_DEFLATED, allowZip64=False
) as f:
for idx, wav in enumerate(wavs):
f.writestr(f"{idx}.mp3", wav_arr_to_mp3_view(wav))
f.writestr(f"{idx}.mp3", pcm_arr_to_mp3_view(wav))
logger.info("Audio generation successful.")
buf.seek(0)

Expand Down
4 changes: 2 additions & 2 deletions examples/cmd/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@

import ChatTTS

from tools.audio import wav_arr_to_mp3_view
from tools.audio import pcm_arr_to_mp3_view
from tools.logger import get_logger

logger = get_logger("Command")


def save_mp3_file(wav, index):
data = wav_arr_to_mp3_view(wav)
data = pcm_arr_to_mp3_view(wav)
mp3_filename = f"output_audio_{index}.mp3"
with open(mp3_filename, "wb") as f:
f.write(data)
Expand Down
1 change: 0 additions & 1 deletion examples/web/funcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from time import sleep

import gradio as gr
import numpy as np

from tools.audio import float_to_int16, has_ffmpeg_installed
from tools.logger import get_logger
Expand Down
3 changes: 3 additions & 0 deletions examples/web/webui.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,9 @@ def make_audio(autoplay, stream):
streaming=stream,
interactive=False,
show_label=True,
waveform_options=gr.WaveformOptions(
sample_rate=24000,
),
)
generate_button.click(
fn=set_buttons_before_generate,
Expand Down
2 changes: 1 addition & 1 deletion tools/audio/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from .mp3 import wav_arr_to_mp3_view
from .pcm import pcm_arr_to_mp3_view
from .ffmpeg import has_ffmpeg_installed
from .np import float_to_int16
2 changes: 1 addition & 1 deletion tools/audio/mp3.py → tools/audio/pcm.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from .av import wav2


def wav_arr_to_mp3_view(wav: np.ndarray):
def pcm_arr_to_mp3_view(wav: np.ndarray):
buf = BytesIO()
with wave.open(buf, "wb") as wf:
wf.setnchannels(1) # Mono channel
Expand Down

0 comments on commit af8a4e3

Please sign in to comment.