alankarmisra / SwiftSiriWaveformView

A UIView subclass that reproduces the waveform effect seen in Siri on iOS 7+. It is a Swift adaptation of the amazing SCSiriWaveformView by Stefan Ceriu.
MIT License
176 stars 29 forks source link

Show voice activity #13

Closed alexbartisro closed 7 years ago

alexbartisro commented 7 years ago

Hello,

I have it implemented based on your sample app, and it looks great. Now I want to show a spike when I get a callback from ios's speech recognition api.

So my animation is now based on

func showVoiceRecord() {
        timer = Timer.scheduledTimer(timeInterval: 0.009, target: self, selector: #selector(animateAudioView), userInfo: nil, repeats: true)
    }

and in my callback I receive a string which is the word the user said

    func setSearchText(_ string: String) {
        audioView.amplitude = 5.0
        change = 2
        searchBar.text = string
        audioView.amplitude = 1.0
        change = 0.01
    }

The thing is that it doesn't do much. The animation change is barely visible.

In my viedDidLoad my setup is

        audioView.density = 1.0
        audioView.phaseShift = 0.1

Any idea how can I achieve this? Thanks!

alankarmisra commented 7 years ago

In setSearchText you raise the amplitude to 5.0 and then change it back to 1.0 which I'm assuming is how you want to display the spike. But these commands will be executed way too quickly resulting in you not seeing any visible change in the amplitude.

I would recommend you introduce a delay between these two changes by moving the last two lines to a different function and then setting up a timer in setSearchText to call this new function. Also call setNeedsDisplay at the end of setSearchText. This will force the view to start displaying the new amplitude and then after a certain delay, your new function should kick it and set your amplitude back to normal.

alexbartisro commented 7 years ago

@alankarmisra yep. Did it like you said. Came out pretty ok. Thank you!