Git Product home page Git Product logo

Comments (7)

dmrschmidt avatar dmrschmidt commented on May 26, 2024 1

Appreciated :) Please free to re-open this or open another issue if there's something else I can help with in the library.

from dswaveformimage.

dmrschmidt avatar dmrschmidt commented on May 26, 2024

Hey @activcoding,

so the short answer is: currently this isn't something that's available as a SwiftUI view directly. It is generally somewhat possible with this WaveformImageDrawer method to draw an image from a an array of Float samples.

But unfortunately that's also not directly usable for you, since what you currently have is "random audio data", that would first need to be unpacked into an actual stream of samples. This is done internally using AVAssetReader which does all the heavy lifting of the different audio encodings etc.

I've just done a quick & dirty SO search on how to get an AVAsset from Data and it seems the best way is to go through writing it to Disk.

That's what I'd have probably recommended in your case and that also seems to be the most direct way in general.

You mentioned you tried that but it didn't work. It definitely will work once the data has been written properly, as long as the audio data is something iOS can read out of the box. Generally speaking, once you wrote the data to disk and an AVPlayer can play it back, WaveformImage will be able to render it.

So long story short, I'd suggest your best way forward is to figure out why the writing to disk doesn't work. Is the format correct? Is the file maybe written with some important header information missing, so that AVFoundation doesn't know what format it is?

from dswaveformimage.

activcoding avatar activcoding commented on May 26, 2024

Thank you @dmrschmidt, I'll try my best.
I very much appreciate your detailed answer, you are a true gem for this community.

from dswaveformimage.

activcoding avatar activcoding commented on May 26, 2024

Found the bug 🎉!
In one of the examples in the readME an m4a file is used:

@State var audioURL = Bundle.main.url(forResource: "example_sound", withExtension: "m4a")!
WaveformView(audioURL: audioURL)

Yesterday I always tried it with a m4a file, but the app keep crashing...
Today I just tried justing a mp3 file, it worked like magic.

from dswaveformimage.

dmrschmidt avatar dmrschmidt commented on May 26, 2024

Great to hear you’ve found the issue.

I’d be really curious to see what the issue with the file may have been. m4a should typically just work. Would it be possible for you to share the file that cause the crash here?

from dswaveformimage.

activcoding avatar activcoding commented on May 26, 2024

Sure.
The audio is from a pet project of me: AI-Voices with ElevenLabs
Here are two audio files, the m4a is not playable and the mp3 is:
But is seems the problem is on the server-side of ElevenLabs 🤦‍♂️, looks like they are sending broken m4a files...

from dswaveformimage.

dmrschmidt avatar dmrschmidt commented on May 26, 2024

Thanks for sharing! Just tried playing it and macOS definitely can't. Tried VLC and it played it. So I opened it in a hex editor, and checked the header bytes to see what format those say it is. Turns out its also just an mp3. If you rename it to mp3, that one also plays on macOS. VLC does a better job at trying to figure put what format files are in. AVFoundation seems to just look at the file ending. So that's that riddle solved :) Sounds like a bug on their end for sure then.

from dswaveformimage.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.