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

streaming_decode.py, relax the audio range from [-1,+1] to [-10,+10] #1448

Merged
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,12 @@ def decode_dataset(
assert audio.dtype == np.float32, audio.dtype

# The trained model is using normalized samples
assert audio.max() <= 1, "Should be normalized to [-1, 1])"
# - this is to avoid sending [-32k,+32k] signal in...
# - some lhotse AudioTransform classes can make the signal
# be out of range [-1, 1], hence the tolerance 10
assert (
np.abs(audio).max() <= 10
), "Should be normalized to [-1, 1], 10 for tolerance..."

samples = torch.from_numpy(audio).squeeze(0)

Expand Down
12 changes: 6 additions & 6 deletions egs/aishell/ASR/zipformer/streaming_decode.py
Original file line number Diff line number Diff line change
Expand Up @@ -597,12 +597,12 @@ def decode_dataset(
assert audio.dtype == np.float32, audio.dtype

# The trained model is using normalized samples
if audio.max() > 1:
logging.warning(
f"The audio should be normalized to [-1, 1], audio.max : {audio.max()}."
f"Clipping to [-1, 1]."
)
audio = np.clip(audio, -1, 1)
# - this is to avoid sending [-32k,+32k] signal in...
# - some lhotse AudioTransform classes can make the signal
# be out of range [-1, 1], hence the tolerance 10
assert (
np.abs(audio).max() <= 10
), "Should be normalized to [-1, 1], 10 for tolerance..."

samples = torch.from_numpy(audio).squeeze(0)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,12 @@ def decode_dataset(
assert audio.dtype == np.float32, audio.dtype

# The trained model is using normalized samples
assert audio.max() <= 1, "Should be normalized to [-1, 1])"
# - this is to avoid sending [-32k,+32k] signal in...
# - some lhotse AudioTransform classes can make the signal
# be out of range [-1, 1], hence the tolerance 10
assert (
np.abs(audio).max() <= 10
), "Should be normalized to [-1, 1], 10 for tolerance..."

samples = torch.from_numpy(audio).squeeze(0)

Expand Down
7 changes: 6 additions & 1 deletion egs/gigaspeech/ASR/zipformer/streaming_decode.py
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,12 @@ def decode_dataset(
assert audio.dtype == np.float32, audio.dtype

# The trained model is using normalized samples
assert audio.max() <= 1, "Should be normalized to [-1, 1])"
# - this is to avoid sending [-32k,+32k] signal in...
# - some lhotse AudioTransform classes can make the signal
# be out of range [-1, 1], hence the tolerance 10
assert (
np.abs(audio).max() <= 10
), "Should be normalized to [-1, 1], 10 for tolerance..."

samples = torch.from_numpy(audio).squeeze(0)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -681,8 +681,14 @@ def decode_dataset(
assert len(audio.shape) == 2
assert audio.shape[0] == 1, "Should be single channel"
assert audio.dtype == np.float32, audio.dtype

# The trained model is using normalized samples
assert audio.max() <= 1, "Should be normalized to [-1, 1])"
# - this is to avoid sending [-32k,+32k] signal in...
# - some lhotse AudioTransform classes can make the signal
# be out of range [-1, 1], hence the tolerance 10
assert (
np.abs(audio).max() <= 10
), "Should be normalized to [-1, 1], 10 for tolerance..."

samples = torch.from_numpy(audio).squeeze(0)
feature = fbank(samples)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -681,8 +681,14 @@ def decode_dataset(
assert len(audio.shape) == 2
assert audio.shape[0] == 1, "Should be single channel"
assert audio.dtype == np.float32, audio.dtype

# The trained model is using normalized samples
assert audio.max() <= 1, "Should be normalized to [-1, 1])"
# - this is to avoid sending [-32k,+32k] signal in...
# - some lhotse AudioTransform classes can make the signal
# be out of range [-1, 1], hence the tolerance 10
assert (
np.abs(audio).max() <= 10
), "Should be normalized to [-1, 1], 10 for tolerance..."

samples = torch.from_numpy(audio).squeeze(0)
feature = fbank(samples)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -673,8 +673,14 @@ def decode_dataset(
assert len(audio.shape) == 2
assert audio.shape[0] == 1, "Should be single channel"
assert audio.dtype == np.float32, audio.dtype

# The trained model is using normalized samples
assert audio.max() <= 1, "Should be normalized to [-1, 1])"
# - this is to avoid sending [-32k,+32k] signal in...
# - some lhotse AudioTransform classes can make the signal
# be out of range [-1, 1], hence the tolerance 10
assert (
np.abs(audio).max() <= 10
), "Should be normalized to [-1, 1], 10 for tolerance..."

samples = torch.from_numpy(audio).squeeze(0)
feature = fbank(samples)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -673,8 +673,14 @@ def decode_dataset(
assert len(audio.shape) == 2
assert audio.shape[0] == 1, "Should be single channel"
assert audio.dtype == np.float32, audio.dtype

# The trained model is using normalized samples
assert audio.max() <= 1, "Should be normalized to [-1, 1])"
# - this is to avoid sending [-32k,+32k] signal in...
# - some lhotse AudioTransform classes can make the signal
# be out of range [-1, 1], hence the tolerance 10
assert (
np.abs(audio).max() <= 10
), "Should be normalized to [-1, 1], 10 for tolerance..."

samples = torch.from_numpy(audio).squeeze(0)
feature = fbank(samples)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,12 @@ def decode_dataset(
assert audio.dtype == np.float32, audio.dtype

# The trained model is using normalized samples
assert audio.max() <= 1, "Should be normalized to [-1, 1])"
# - this is to avoid sending [-32k,+32k] signal in...
# - some lhotse AudioTransform classes can make the signal
# be out of range [-1, 1], hence the tolerance 10
assert (
np.abs(audio).max() <= 10
), "Should be normalized to [-1, 1], 10 for tolerance..."

samples = torch.from_numpy(audio).squeeze(0)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,12 @@ def decode_dataset(
assert audio.dtype == np.float32, audio.dtype

# The trained model is using normalized samples
assert audio.max() <= 1, "Should be normalized to [-1, 1])"
# - this is to avoid sending [-32k,+32k] signal in...
# - some lhotse AudioTransform classes can make the signal
# be out of range [-1, 1], hence the tolerance 10
assert (
np.abs(audio).max() <= 10
), "Should be normalized to [-1, 1], 10 for tolerance..."

samples = torch.from_numpy(audio).squeeze(0)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,12 @@ def decode_dataset(
assert audio.dtype == np.float32, audio.dtype

# The trained model is using normalized samples
assert audio.max() <= 1, "Should be normalized to [-1, 1])"
# - this is to avoid sending [-32k,+32k] signal in...
# - some lhotse AudioTransform classes can make the signal
# be out of range [-1, 1], hence the tolerance 10
assert (
np.abs(audio).max() <= 10
), "Should be normalized to [-1, 1], 10 for tolerance..."

samples = torch.from_numpy(audio).squeeze(0)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,12 @@ def decode_dataset(
assert audio.dtype == np.float32, audio.dtype

# The trained model is using normalized samples
assert audio.max() <= 1, "Should be normalized to [-1, 1])"
# - this is to avoid sending [-32k,+32k] signal in...
# - some lhotse AudioTransform classes can make the signal
# be out of range [-1, 1], hence the tolerance 10
assert (
np.abs(audio).max() <= 10
), "Should be normalized to [-1, 1], 10 for tolerance..."

samples = torch.from_numpy(audio).squeeze(0)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,12 @@ def decode_dataset(
assert audio.dtype == np.float32, audio.dtype

# The trained model is using normalized samples
assert audio.max() <= 1, "Should be normalized to [-1, 1])"
# - this is to avoid sending [-32k,+32k] signal in...
# - some lhotse AudioTransform classes can make the signal
# be out of range [-1, 1], hence the tolerance 10
assert (
np.abs(audio).max() <= 10
), "Should be normalized to [-1, 1], 10 for tolerance..."

samples = torch.from_numpy(audio).squeeze(0)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,12 @@ def decode_dataset(
assert audio.dtype == np.float32, audio.dtype

# The trained model is using normalized samples
assert audio.max() <= 1, "Should be normalized to [-1, 1])"
# - this is to avoid sending [-32k,+32k] signal in...
# - some lhotse AudioTransform classes can make the signal
# be out of range [-1, 1], hence the tolerance 10
assert (
np.abs(audio).max() <= 10
), "Should be normalized to [-1, 1], 10 for tolerance..."

samples = torch.from_numpy(audio).squeeze(0)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,12 @@ def decode_dataset(
assert audio.dtype == np.float32, audio.dtype

# The trained model is using normalized samples
assert audio.max() <= 1, "Should be normalized to [-1, 1])"
# - this is to avoid sending [-32k,+32k] signal in...
# - some lhotse AudioTransform classes can make the signal
# be out of range [-1, 1], hence the tolerance 10
assert (
np.abs(audio).max() <= 10
), "Should be normalized to [-1, 1], 10 for tolerance..."

samples = torch.from_numpy(audio).squeeze(0)

Expand Down
7 changes: 6 additions & 1 deletion egs/librispeech/ASR/zipformer/streaming_decode.py
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,12 @@ def decode_dataset(
assert audio.dtype == np.float32, audio.dtype

# The trained model is using normalized samples
assert audio.max() <= 1, "Should be normalized to [-1, 1])"
# - this is to avoid sending [-32k,+32k] signal in...
# - some lhotse AudioTransform classes can make the signal
# be out of range [-1, 1], hence the tolerance 10
assert (
np.abs(audio).max() <= 10
), "Should be normalized to [-1, 1], 10 for tolerance..."

samples = torch.from_numpy(audio).squeeze(0)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,14 @@ def decode_dataset(
assert audio.shape[0] == 1, "Should be single channel"
assert audio.dtype == np.float32, audio.dtype

# The trained model is using normalized samples
# - this is to avoid sending [-32k,+32k] signal in...
# - some lhotse AudioTransform classes can make the signal
# be out of range [-1, 1], hence the tolerance 10
assert (
np.abs(audio).max() <= 10
), "Should be normalized to [-1, 1], 10 for tolerance..."

samples = torch.from_numpy(audio).squeeze(0)

fbank = Fbank(opts)
Expand Down
12 changes: 6 additions & 6 deletions egs/wenetspeech/ASR/zipformer/streaming_decode.py
Original file line number Diff line number Diff line change
Expand Up @@ -597,12 +597,12 @@ def decode_dataset(
assert audio.dtype == np.float32, audio.dtype

# The trained model is using normalized samples
if audio.max() > 1:
logging.warning(
f"The audio should be normalized to [-1, 1], audio.max : {audio.max()}."
f"Clipping to [-1, 1]."
)
audio = np.clip(audio, -1, 1)
# - this is to avoid sending [-32k,+32k] signal in...
# - some lhotse AudioTransform classes can make the signal
# be out of range [-1, 1], hence the tolerance 10
assert (
np.abs(audio).max() <= 10
), "Should be normalized to [-1, 1], 10 for tolerance..."

samples = torch.from_numpy(audio).squeeze(0)

Expand Down
Loading