File tree Expand file tree Collapse file tree 2 files changed +16
-9
lines changed
src/transformers/models/xcodec Expand file tree Collapse file tree 2 files changed +16
-9
lines changed Original file line number Diff line number Diff line change @@ -59,16 +59,27 @@ audio_sample = dummy_dataset[-1]["audio"]["array"]
5959inputs = feature_extractor(raw_audio = audio_sample, sampling_rate = feature_extractor.sampling_rate, return_tensors = " pt" )
6060
6161encoder_outputs = model.encode(inputs[" input_values" ])
62- audio_codes = encoder_outputs.audio_codes
63- decoder_outputs = model.decode(audio_codes)
62+ decoder_outputs = model.decode(encoder_outputs.audio_codes)
6463audio_values = decoder_outputs.audio_values
6564
6665# or the equivalent with a forward pass
67- outputs = model(inputs[" input_values" ])
68- audio_codes = outputs.audio_codes
69- audio_values = outputs.audio_values
66+ audio_values = model(inputs[" input_values" ]).audio_values
67+
68+ ```
69+ To listen to the original and reconstructed audio, run the snippet below and then open the generated ` original.wav ` and ` reconstruction.wav ` files in your music player to compare.
70+
71+ ``` python
72+ import soundfile as sf
73+
74+ original = audio_sample
75+ reconstruction = audio_values[0 ].cpu().detach().numpy()
76+ sampling_rate = feature_extractor.sampling_rate
77+
78+ sf.write(" original.wav" , original, sampling_rate)
79+ sf.write(" reconstruction.wav" , reconstruction.T, sampling_rate)
7080```
7181
82+
7283## XcodecConfig
7384
7485[[ autodoc]] XcodecConfig
Original file line number Diff line number Diff line change @@ -179,10 +179,6 @@ def __init__(
179179 def frame_rate (self ) -> int :
180180 return math .ceil (self .sample_rate / np .prod (self .acoustic_model_config .upsampling_ratios ))
181181
182- @property
183- def bits_per_codebook (self ) -> int :
184- return int (math .log2 (self .codebook_size ))
185-
186182 @property
187183 def hop_length (self ) -> int :
188184 return int (np .prod (self .acoustic_model_config .downsampling_ratios ))
You can’t perform that action at this time.
0 commit comments