3

I have some data that I assume is wav data. If I use:

soundfile.write(filepath, my_data, samplerate)

, then it correctly writes a wav file. But I want to somehow convert that wav data to int16 as currently it's some sort of float:

[0.0018415  0.00730521 0.01155283 ... 0.10048427 0.09344029 0.08903081]

with

max 0.3002103
min -0.33075073

It came from a process in https://github.com/santi-pdp/segan_pytorch

Is there some way for me to convert to int16 this without having to save and then read a file?

13
  • 2
    as currently it's some sort of float Can you check what it actually is? You've given practically no information here, can you please be more specific? Where is the file coming from? What libraries are you using? Commented Dec 24, 2019 at 2:27
  • Added more detail outlining the problem Commented Dec 24, 2019 at 14:00
  • It's a numpy array? What's the .dtype? Do you want to just change the type to int16, or do you want to scale the data as well? Commented Dec 24, 2019 at 15:11
  • I want to scale the data to the same that would have happened if I read with soundfile.read(dtype=int16) Commented Dec 24, 2019 at 15:18
  • Is the data currently in the range [0, 1[ ? You write that you assume the data is in the wav format, can you be more specific? Commented Dec 24, 2019 at 15:19

1 Answer 1

5

Answer was simple enough:

my_data = (my_data * 32767).astype(np.int16)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.