Specifying raw type to `build_array()`
SamuelLarkin opened this issue · 2 comments
SamuelLarkin commented
Hi,
I'm attempting to translate
sox -r {SAMPLE_RATE} -b {BITS} -e {ENCODING} -c {NUM_CHANNEL} -t raw {raw_audio_file.name} {wav_audio_file.name}
to a call to build_array()
but I can't seem to be able to specify the equivalent of -t raw
.
Code
tfm2wav = sox.Transformer()
tfm2wav.set_input_format(
file_type="raw",
rate=SAMPLE_RATE,
bits=BITS,
channels=NUM_CHANNEL,
encoding=ENCODING,
)
tfm2wav.set_output_format(
file_type="wav",
rate=SAMPLE_RATE,
bits=BITS,
channels=NUM_CHANNEL,
encoding=ENCODING,
)
audio = tfm2wav.build_array(
input_filepath=raw_audio_file.name,
)
tfm2wav.build_file(
input_array=audio,
output_filepath=wav_audio_file.name,
sample_rate_in=SAMPLE_RATE,
)
Error Message
{
"errorMessage": "list index out of range",
"errorType": "IndexError",
"requestId": "d89c028b-e894-4596-89fd-0a9f19017103",
"stackTrace": [
" File \"/var/task/lambda_function.py\", line 103, in handler\n raise e\n",
" File \"/var/task/lambda_function.py\", line 91, in handler\n denoise(noisy_audio_file.name, denoised_audio_file.name)\n",
" File \"/var/task/lambda_function.py\", line 157, in denoise\n audio = tfm2wav.build_array(\n",
" File \"/opt/python/sox/transform.py\", line 793, in build_array\n encoding_out = [\n"
]
}
[ERROR] 2022-11-01T14:34:13.338Z d89c028b-e894-4596-89fd-0a9f19017103 list index out of range
[ERROR] IndexError: list index out of range
Traceback (most recent call last):
File "/var/task/lambda_function.py", line 103, in handler
raise e
File "/var/task/lambda_function.py", line 91, in handler
denoise(noisy_audio_file.name, denoised_audio_file.name)
File "/var/task/lambda_function.py", line 157, in denoise
audio = tfm2wav.build_array(
File "/opt/python/sox/transform.py", line 793, in build_array
encoding_out = [END RequestId: d89c028b-e894-4596-89fd-0a9f19017103
zoldaten commented
just remove '[0]' in /opt/python/sox/transform.py", line 793
jsalsman commented
Can confirm in v1.4.1:
Python 3.10.11 (main, Apr 4 2023, 22:10:32) [GCC 12.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sox
>>> tfm=sox.Transformer()
>>> tfm.set_input_format(file_type='raw', rate=16000, bits=16,
... channels=1, encoding='signed-integer')
>>> tfm.silence(min_silence_duration=0.25,
... buffer_around_silence=True)
<sox.transform.Transformer object at 0x7fdb8e043460>
>>> pcm = tfm.build_array('static/audio-22212508.raw')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/runner/webrec/.pythonlibs/lib/python3.10/site-packages/sox/transform.py", line 793, in build_array
encoding_out = [
IndexError: list index out of range
>>>
just remove '[0]' in /opt/python/sox/transform.py", line 793
If you mean at https://github.com/rabitt/pysox/blob/master/sox/transform.py#L825 that doesn't work, sorry:
>>> pcm = tfm.build_array('static/audio-22212508.raw')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/runner/webrec/.pythonlibs/lib/python3.10/site-packages/sox/transform.py", line 829, in build_array
raise ValueError("invalid n_bits {}".format(n_bits))
ValueError: invalid n_bits 0
>>>