dmrschmidt / DSWaveformImage

Generate waveform images from audio files on iOS, macOS & visionOS in Swift. Native SwiftUI & UIKit views.
MIT License
978 stars 109 forks source link

timer with sound wave #55

Closed ducduy20 closed 1 year ago

ducduy20 commented 1 year ago

is there any way to use timer and wave?

ducduy20 commented 1 year ago

I want to record to have timer along with sound wave to sync it

dmrschmidt commented 1 year ago

You can have a look at https://github.com/dmrschmidt/DSWaveformImage/blob/main/Example/DSWaveformImageExample-iOS/SCAudioManager.m which uses a timer and the recorder‘s currentTime property.

you’ll want to do sth similar.

ducduy20 commented 1 year ago

Screenshot 2023-01-04 at 16 03 46 how can i call currentTime on view and use it

dmrschmidt commented 1 year ago

Hey @ducduy20,

this is getting a bit too far out of scope for the support I can provide here as it’s not related to the library anymore. For general questions on software development topics, please consider stackoverflow etc.

Your question is quite imprecise, so it’s hard to guess what you are looking for. If you’re looking to get a good answer, try being more descriptive what you would like to achieve. Plus what you have tried so far and why that doesn’t work. Ie by providing error messages or a detailed description of the problem.

I can see that you are already using currentTime in the code, so I’m not quite sure what you are looking for. Do you mean you don’t know how to make currentTime available inside of a view to display it?

If that’s the case, you’ll probably want to look at creating an ObservableObject which owns the recorder, and exposes an @Published var currentTime or the like. Could already be the formatted string.

ducduy20 commented 1 year ago

Hey @dmrschmidt Thanks for reply because here i use your wave for recording and i want to use timer timer. So because of the eigen counter and the eigenwave, does it affect the drawing ability of the wave. I apologize for asking things that are not related to the library

dmrschmidt commented 1 year ago

What is an eigen counter and an eigenwave? I don't suppose you mean this as it really doesn't matter what kind of wave you're drawing, as long as it can be represented as a 1-dimensional list of values of magnitudes.

The drawing of the wave has some performance implications of course, if that's what you mean. That timer, which you set to 0.01 (I believe that's seconds) is a recommendation to the OS. It may not be able to fulfill this request if too much is clogging the CPU. However, as you typically don't want to update a timer more often than once per second, there should be absolutely no noticeable downgrading effect whatsoever of drawing the wave and the numerical timer somewhere in the view as 1:42m or similar.

Also you won't be recalculating the wave constantly and instead only once if you're doing it like in that progress indicator question you also wrote a comment in.

ducduy20 commented 1 year ago

Thank you @dmrschmidt

ducduy20 commented 1 year ago

hey @dmrschmidt There is one more problem, i don't know if it is related to the library? . But is there a way to change the song duration to 0 to 1 so that I can use the wave to play back the audio

dmrschmidt commented 1 year ago

Please really try to be more descriptive with your questions. It is hard to understand what you are trying to achieve. If English is not your mother tongue, maybe try using Google Translate or - nowadays - ChatGPT etc.

How do you want to play the audio with the waveform? Do you mean dragging some kind of progress indicator around so you can move the play position to a specific position?

If the progress value for the overlay waveform you’re probably talking about is going from 0…1, then you will only need to multiply that value with the total duration, say 4:24m. So a progress of 0.5 for a total duration of 4:24m would give you 2:12m. TimeInterval, which is what AVPlayer uses is just a typealias for Double. On 10. Jan 2023 at 07:57 +0530, ducduy20 @.***>, wrote:

hey @dmrschmidt There is one more problem, i don't know if it is related to the library? . But is there a way to change the song duration to 0 to 1 so that I can use the wave to play back the audio — Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you were mentioned.Message ID: @.***>