Browse Source

Fix pyaudio with ruff

tags/v0.3.9-rc1
haixuantao 1 year ago
parent
commit
6a9b86d9a1
4 changed files with 9 additions and 8 deletions
  1. +6
    -3
      node-hub/dora-distil-whisper/dora_distil_whisper/main.py
  2. +1
    -1
      node-hub/dora-pyaudio/dora_pyaudio/__init__.py
  3. +0
    -1
      node-hub/dora-pyaudio/dora_pyaudio/__main__.py
  4. +2
    -3
      node-hub/dora-pyaudio/dora_pyaudio/main.py

+ 6
- 3
node-hub/dora-distil-whisper/dora_distil_whisper/main.py View File

@@ -47,7 +47,8 @@ def load_model():


def load_model_mlx():
from lightning_whisper_mlx import LightningWhisperMLX # noqa
# noqa: disable: import-error
from lightning_whisper_mlx import LightningWhisperMLX

whisper = LightningWhisperMLX(model="distil-large-v3", batch_size=12, quant=None)
return whisper
@@ -78,7 +79,8 @@ def cut_repetition(text, min_repeat_length=4, max_repeat_length=50):
if sum(1 for char in text if "\u4e00" <= char <= "\u9fff") / len(text) > 0.5:
# Chinese text processing
for repeat_length in range(
min_repeat_length, min(max_repeat_length, len(text) // 2),
min_repeat_length,
min(max_repeat_length, len(text) // 2),
):
for i in range(len(text) - repeat_length * 2 + 1):
chunk1 = text[i : i + repeat_length]
@@ -90,7 +92,8 @@ def cut_repetition(text, min_repeat_length=4, max_repeat_length=50):
# Non-Chinese (space-separated) text processing
words = text.split()
for repeat_length in range(
min_repeat_length, min(max_repeat_length, len(words) // 2),
min_repeat_length,
min(max_repeat_length, len(words) // 2),
):
for i in range(len(words) - repeat_length * 2 + 1):
chunk1 = " ".join(words[i : i + repeat_length])


+ 1
- 1
node-hub/dora-pyaudio/dora_pyaudio/__init__.py View File

@@ -5,7 +5,7 @@ readme_path = os.path.join(os.path.dirname(os.path.dirname(__file__)), "README.m

# Read the content of the README file
try:
with open(readme_path, "r", encoding="utf-8") as f:
with open(readme_path, encoding="utf-8") as f:
__doc__ = f.read()
except FileNotFoundError:
__doc__ = "README file not found."

+ 0
- 1
node-hub/dora-pyaudio/dora_pyaudio/__main__.py View File

@@ -1,5 +1,4 @@
from .main import main


if __name__ == "__main__":
main()

+ 2
- 3
node-hub/dora-pyaudio/dora_pyaudio/main.py View File

@@ -12,17 +12,16 @@ p = pyaudio.PyAudio()


def play_audio(
audio_array: pa.array, sample_rate: int, stream: pyaudio.Stream = None
audio_array: pa.array, sample_rate: int, stream: pyaudio.Stream = None,
) -> pyaudio.Stream:
"""Play audio using pyaudio and replace stream if already exists"""

if np.issubdtype(audio_array.dtype, np.floating):
max_val = np.max(np.abs(audio_array))
audio_array = (audio_array / max_val) * 32767
audio_array = audio_array.astype(np.int16)
if stream is None:
stream = p.open(
format=pyaudio.paInt16, channels=1, rate=sample_rate, output=True
format=pyaudio.paInt16, channels=1, rate=sample_rate, output=True,
)
stream.write(audio_array.tobytes())
return stream


Loading…
Cancel
Save