marl / marl/pysox

Specifying raw type to `build_array()`

Open
#154 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
540
Forks
83
PR merge metrics
No merged PRs in 30d

Description

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

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in sox/transform.py at build_array around line 793, then trace how set_input_format handles file_type="raw" and how the supplied build_file path handles the same format. Reproduce the provided call and verify that raw input reaches build_array without the IndexError and can be converted to WAV.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
audio-video-rtc
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.