Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b5bb2e4

Browse files
author
Arlin
committed
Add local voice pitch by mac
1 parent 5dbf267 commit b5bb2e4

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

macOS/APIExample/Commons/StatisticsInfo.swift

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ struct StatisticsInfo {
1515
var videoStats : AgoraRtcLocalVideoStats?
1616
var audioStats : AgoraRtcLocalAudioStats?
1717
var audioVolume : UInt?
18+
var audioPitch : UInt?
1819
}
1920

2021
struct RemoteInfo {
@@ -119,6 +120,17 @@ struct StatisticsInfo {
119120
}
120121
}
121122

123+
mutating func updatePitch(_ pitch: UInt) {
124+
switch type {
125+
case .local(let info):
126+
var new = info
127+
new.audioPitch = pitch
128+
self.type = .local(new)
129+
case .remote(_):
130+
break
131+
}
132+
}
133+
122134
func description(audioOnly:Bool) -> String {
123135
var full: String
124136
switch type {
@@ -149,6 +161,9 @@ struct StatisticsInfo {
149161
if let volume = info.audioVolume {
150162
results.append("Volume: \(volume)")
151163
}
164+
if let pitch = info.audioPitch {
165+
results.append("Pitch: \(pitch)")
166+
}
152167

153168
if let channelStats = info.channelStats, let audioStats = info.audioStats {
154169
results.append("LM Delay: \(channelStats.lastmileDelay)ms")

macOS/APIExample/Examples/Basic/JoinChannelAudio/JoinChannelAudio.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,8 @@ class JoinChannelAudioMain: BaseViewController {
334334
agoraKit.setClientRole(.broadcaster)
335335
// enable volume indicator
336336
agoraKit.enableAudioVolumeIndication(200, smooth: 3, report_vad: true)
337+
// enable local voice pitch
338+
agoraKit.enableLocalVoicePitchCallback(200)
337339

338340
// start joining channel
339341
// 1. Users can only see each other after they join the
@@ -485,4 +487,10 @@ extension JoinChannelAudioMain: AgoraRtcEngineDelegate {
485487
}
486488
}
487489
}
490+
491+
/// Reports local user voice pitch
492+
/// @params pitchInHz pitch with Hz of local user
493+
func rtcEngine(_ engine: AgoraRtcEngineKit, reportLocalVoicePitchFrequency pitchInHz: Int) {
494+
videos[0].statsInfo?.updatePitch(UInt(pitchInHz))
495+
}
488496
}

0 commit comments

Comments
 (0)