facebookresearch / playtorch

PlayTorch is a framework for rapidly creating mobile AI experiences.
https://playtorch.dev/
MIT License
830 stars 101 forks source link

It is not possible to convert audio float32 tensor to playable uint8 audio expected by .audioFromBytes() #202

Closed BlazJurisic closed 1 year ago

BlazJurisic commented 1 year ago

Version

No response

Problem Area

react-native-pytorch-core (core package)

Steps to Reproduce

const outputAudioFloat32 = await model.forward(torch.zeros(80000))
const _outputAudio = await experimental.audioFromBytes([...outputAudioFloat32.data()], 16000)
  _outputAudio.play()

Expected Results

audio plays as it should

Code example, screenshot, or link to repository

broken audio..

I have tried with blobs, Arrays and buffers, literally everything

BlazJurisic commented 1 year ago

Figured it out finally, you have to transform first to pcm 16 and to bytes (which are uint8) afterwards.