Skip to content

A TTS that fits in your CPU (and pocket)

Python

Immutable defaults in seanet; document the two open() call sites (#260)

manu-lma61b7878bb71
diff --git a/pocket_tts/data/audio.py b/pocket_tts/data/audio.py
index a5358b4..734acba 100644
--- a/pocket_tts/data/audio.py
+++ b/pocket_tts/data/audio.py
@@ -73,7 +73,8 @@ class StreamingWAVWriter:
"""Initialize WAV writer with header."""
# For stdout streaming, we need to handle the unseekable stream case
# The wave module supports unseekable streams since Python 3.4
- self.wave_writer = wave.open(self.output_stream, "wb")
+ # Closed with the underlying stream by the caller's `with f:` block.
+ self.wave_writer = wave.open(self.output_stream, "wb") # noqa: SIM115
self.wave_writer.setnchannels(1) # Mono
self.wave_writer.setsampwidth(2) # 16-bit
self.wave_writer.setframerate(sample_rate)
@@ -148,7 +149,7 @@ def stream_audio_chunks(
elif is_file_like(path):
f = path
else:
- f = open(path, "wb")
+ f = open(path, "wb") # noqa: SIM115 -- closed by the `with f:` below
with f:
if path is not None:
diff --git a/pocket_tts/modules/seanet.py b/pocket_tts/modules/seanet.py
index 0971852..9ceff05 100644
--- a/pocket_tts/modules/seanet.py
+++ b/pocket_tts/modules/seanet.py
@@ -1,3 +1,5 @@
+from collections.abc import Sequence
+
import numpy as np
import torch.nn as nn
@@ -8,8 +10,8 @@ class SEANetResnetBlock(nn.Module):
def __init__(
self,
dim: int,
- kernel_sizes: list[int] = [3, 1],
- dilations: list[int] = [1, 1],
+ kernel_sizes: Sequence[int] = (3, 1),
+ dilations: Sequence[int] = (1, 1),
pad_mode: str = "reflect",
compress: int = 2,
):
@@ -48,7 +50,7 @@ class SEANetEncoder(nn.Module):
dimension: int = 128,
n_filters: int = 32,
n_residual_layers: int = 3,
- ratios: list[int] = [8, 5, 4, 2],
+ ratios: Sequence[int] = (8, 5, 4, 2),
kernel_size: int = 7,
last_kernel_size: int = 7,
residual_kernel_size: int = 3,
@@ -120,7 +122,7 @@ class SEANetDecoder(nn.Module):
dimension: int = 128,
n_filters: int = 32,
n_residual_layers: int = 3,
- ratios: list[int] = [8, 5, 4, 2],
+ ratios: Sequence[int] = (8, 5, 4, 2),
kernel_size: int = 7,
last_kernel_size: int = 7,
residual_kernel_size: int = 3,
@@ -132,7 +134,7 @@ class SEANetDecoder(nn.Module):
self.dimension = dimension
self.channels = channels
self.n_filters = n_filters
- self.ratios = ratios
+ self.ratios = list(ratios)
del ratios
self.n_residual_layers = n_residual_layers
self.hop_length = int(np.prod(self.ratios))