Last active
December 6, 2021 10:44
-
-
Save maxxfrazer/549427c6e95921b6114f84a072269adb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct ContentView: View { | |
@State var joinedChannel: Bool = false | |
static var agview: AgoraViewer = { | |
AgoraViewer( | |
connectionData: AgoraConnectionData( | |
appId: AppKeys.agoraAppId | |
), | |
style: .floating | |
) | |
}() | |
var body: some View { | |
ZStack { | |
VideoCallView(joinedChannel: $joinedChannel) | |
if !joinedChannel { | |
Button("Join Channel") { | |
self.joinChannel() | |
} | |
} | |
} | |
} | |
func joinChannel() { | |
self.joinedChannel = true | |
ContentView.agview.join( | |
channel: "test", with: AppKeys.agoraToken, | |
as: .broadcaster | |
) | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
enum VoiceEffect { | |
case echo(EchoVoiceEffectConfiguration) | |
case reverb(ReverbVoiceEffectConfiguration) | |
case flanger(FlangerVoiceEffectConfiguration) | |
case pitch(PitchShiftVoiceEffectConfiguration) | |
} | |
func getVoiceFilter(from name: String) -> VoiceEffect? { | |
if name == "echo" { | |
return .echo(EchoVoiceEffectConfiguration(mix: 1.0)) | |
} else if name == "reverb" { | |
return .reverb(ReverbVoiceEffectConfiguration( | |
dry: 0.9, wet: 0.3, mix: 0.6, width: 1.0, | |
damp: 1.0, roomSize: 1.0, preDelay: 300.0, lowCut: 5.0 | |
)) | |
} else if name == "flanger" { | |
return .flanger(FlangerVoiceEffectConfiguration( | |
wet: 1.0, depth: 1.0, lfoBeats: 30.0, bpm: 100.0, stereo: true | |
)) | |
} else if name == "pitch shift" { | |
return .pitch(PitchShiftVoiceEffectConfiguration(shift: 500)) | |
} | |
return nil | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct VideoCallView: View { | |
// other content... | |
@State var voiceFxRegistered = false | |
func setVoiceFxParam(to voiceName: String) { | |
if !self.voiceFxRegistered { | |
self.registerVoiceFX() | |
} | |
// Apply Voice Effects... | |
} | |
func registerVoiceFX() { | |
// Set API Credentials | |
ContentView.agview.viewer.setExtensionProperty( | |
VoiceFiltersAgoraExtensionVendor, extension: VoiceFiltersAgoraExtensionName, | |
key: VoiceFiltersAgoraExtensionApiKey, value: AppKeys.voiceFxApiKey | |
) | |
ContentView.agview.viewer.setExtensionProperty( | |
VoiceFiltersAgoraExtensionVendor, extension: VoiceFiltersAgoraExtensionName, | |
key: VoiceFiltersAgoraExtensionApiSecret, value: AppKeys.voiceFxApiSecret | |
) | |
ContentView.agview.viewer.enableExtension( | |
withVendor: VoiceFiltersAgoraExtensionVendor, | |
extension: VoiceFiltersAgoraExtensionName, enabled: true | |
) | |
self.voiceFxRegistered = true | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct VideoCallView: View { | |
// other content... | |
static let voiceFilter: SynervozVoiceFilter = SynervozVoiceFilter() | |
func setVoiceFxParam(to voiceName: String) { | |
if !self.voiceFxRegistered { | |
self.registerVoiceFX() | |
} | |
let newVoice = self.getVoiceFilter(from: voiceName) | |
let agoraEngine = ContentView.agview.viewer.agkit | |
switch newVoice { | |
case .echo(let echoConfig): | |
VideoCallView.voiceFilter.setEcho(echoConfig, inEngine: agoraEngine) | |
case .reverb(let reverbConfig): | |
VideoCallView.voiceFilter.setReverbConfiguration(reverbConfig, inEngine: agoraEngine) | |
case .flanger(let flangerConfig): | |
VideoCallView.voiceFilter.setFlangerConfiguration(flangerConfig, inEngine: agoraEngine) | |
case .pitch(let pitchShiftConfig): | |
VideoCallView.voiceFilter.setPitchShiftConfiguration(pitchShiftConfig, inEngine: agoraEngine) | |
case .none: break | |
} | |
VideoCallView.voiceFilter.enableEcho("echo" == voiceName, inEngine: agoraEngine) | |
VideoCallView.voiceFilter.enableReverb("reverb" == voiceName, inEngine: agoraEngine) | |
VideoCallView.voiceFilter.enableFlanger("flanger" == voiceName, inEngine: agoraEngine) | |
VideoCallView.voiceFilter.enablePitchShift("pitch shift" == voiceName, inEngine: agoraEngine) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment