Skip to content

Commit

Permalink
Merge branch 'master' into yulin/word-boundary
Browse files Browse the repository at this point in the history
  • Loading branch information
trrwilson authored Mar 31, 2022
2 parents 72701e8 + 9b26a1a commit 6b3703a
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 90 deletions.
16 changes: 6 additions & 10 deletions samples/speaker_recognition/independent_identification.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (
"time"

"github.com/Microsoft/cognitive-services-speech-sdk-go/audio"
"github.com/Microsoft/cognitive-services-speech-sdk-go/common"
"github.com/Microsoft/cognitive-services-speech-sdk-go/speaker"
"github.com/Microsoft/cognitive-services-speech-sdk-go/samples/helpers"
"github.com/Microsoft/cognitive-services-speech-sdk-go/speech"
)

Expand All @@ -20,8 +20,8 @@ func GetNewVoiceProfileFromClient(client *speaker.VoiceProfileClient, expectedTy
fmt.Println("Got an error creating profile: ", outcome.Error.Error())
return nil
}
profile := outcome.profile
id, err := profile.Id()
profile := outcome.Profile
_, err := profile.Id()
if err != nil {
fmt.Println("Unexpected error creating profile id: ", err)
return nil
Expand All @@ -38,9 +38,9 @@ func GetNewVoiceProfileFromClient(client *speaker.VoiceProfileClient, expectedTy
return profile
}

func EnrollProfile(client *speaker.VoiceProfileClient, profile *speaker.VoiceProfile, audioConfig audio.AudioConfig) {
func EnrollProfile(client *speaker.VoiceProfileClient, profile *speaker.VoiceProfile, audioConfig *audio.AudioConfig) {
enrollmentReason, currentReason := common.EnrollingVoiceProfile, common.EnrollingVoiceProfile
var currentResult *VoiceProfileEnrollmentResult
var currentResult *speaker.VoiceProfileEnrollmentResult
expectedEnrollmentCount := 1
for currentReason == enrollmentReason {
enrollFuture := client.EnrollProfileAsync(profile, audioConfig)
Expand All @@ -59,10 +59,6 @@ func EnrollProfile(client *speaker.VoiceProfileClient, profile *speaker.VoicePro
if currentReason != common.EnrolledVoiceProfile {
fmt.Println("Unexpected result enrolling profile: ", currentResult)
}
expectedEnrollmentsLength := big.NewInt(0)
if currentResult.RemainingEnrollmentsLength.Int64() != expectedEnrollmentsLength.Int64() {
fmt.Println("Unexpected remaining enrollment length for profile: ", currentResult.RemainingEnrollmentsLength)
}
}

func DeleteProfile(client *speaker.VoiceProfileClient, profile *speaker.VoiceProfile) {
Expand Down Expand Up @@ -127,7 +123,7 @@ func IndependentIdentification(subscription string, region string, file string)
speakerRecognizer, err := speaker.NewSpeakerRecognizerFromConfig(config, identifyAudioConfig)
if err != nil {
fmt.Println("Got an error: ", err)
return nil
return
}
identifyFuture := speakerRecognizer.IdentifyOnceAsync(model)
identifyOutcome := <-identifyFuture
Expand Down
69 changes: 2 additions & 67 deletions samples/speaker_recognition/independent_verification.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,75 +9,10 @@ import (

"github.com/Microsoft/cognitive-services-speech-sdk-go/audio"
"github.com/Microsoft/cognitive-services-speech-sdk-go/speaker"
"github.com/Microsoft/cognitive-services-speech-sdk-go/samples/helpers"
"github.com/Microsoft/cognitive-services-speech-sdk-go/common"
"github.com/Microsoft/cognitive-services-speech-sdk-go/speech"
)

func GetNewVoiceProfileFromClient(client *speaker.VoiceProfileClient, expectedType common.VoiceProfileType) *speaker.VoiceProfile {
future := client.CreateProfileAsync(expectedType, "en-US")
outcome := <-future
if outcome.Failed() {
fmt.Println("Got an error creating profile: ", outcome.Error.Error())
return nil
}
profile := outcome.profile
id, err := profile.Id()
if err != nil {
fmt.Println("Unexpected error creating profile id: ", err)
return nil
}
profileType, err := profile.Type();
if err != nil {
fmt.Println("Unexpected error getting profile type: ", err)
return nil
}
if profileType != expectedType {
fmt.Println("Profile type does not match expected type")
return nil
}
return profile
}

func EnrollProfile(client *speaker.VoiceProfileClient, profile *speaker.VoiceProfile, audioConfig audio.AudioConfig) {
enrollmentReason, currentReason := common.EnrollingVoiceProfile, common.EnrollingVoiceProfile
var currentResult *VoiceProfileEnrollmentResult
expectedEnrollmentCount := 1
for currentReason == enrollmentReason {
enrollFuture := client.EnrollProfileAsync(profile, audioConfig)
enrollOutcome := <-enrollFuture
if enrollOutcome.Failed() {
fmt.Println("Got an error enrolling profile: ", enrollOutcome.Error.Error())
return
}
currentResult = enrollOutcome.Result
currentReason = currentResult.Reason
if currentResult.EnrollmentsCount != expectedEnrollmentCount {
fmt.Println("Unexpected enrollments for profile: ", currentResult.RemainingEnrollmentsCount)
}
expectedEnrollmentCount += 1
}
if currentReason != common.EnrolledVoiceProfile {
fmt.Println("Unexpected result enrolling profile: ", currentResult)
}
expectedEnrollmentsLength := big.NewInt(0)
if currentResult.RemainingEnrollmentsLength.Int64() != expectedEnrollmentsLength.Int64() {
fmt.Println("Unexpected remaining enrollment length for profile: ", currentResult.RemainingEnrollmentsLength)
}
}

func DeleteProfile(client *speaker.VoiceProfileClient, profile *speaker.VoiceProfile) {
deleteFuture := client.DeleteProfileAsync(profile)
deleteOutcome := <-deleteFuture
if deleteOutcome.Failed() {
fmt.Println("Got an error deleting profile: ", deleteOutcome.Error.Error())
return
}
result := deleteOutcome.Result
if result.Reason != common.DeletedVoiceProfile {
fmt.Println("Unexpected result deleting profile: ", result)
}
}

func IndependentVerification(subscription string, region string, file string) {
config, err := speech.NewSpeechConfigFromSubscription(subscription, region)
if err != nil {
Expand Down Expand Up @@ -126,7 +61,7 @@ func IndependentVerification(subscription string, region string, file string) {
speakerRecognizer, err := speaker.NewSpeakerRecognizerFromConfig(config, verifyAudioConfig)
if err != nil {
fmt.Println("Got an error: ", err)
return nil
return
}
verifyFuture := speakerRecognizer.VerifyOnceAsync(model)
verifyOutcome := <-verifyFuture
Expand Down
22 changes: 11 additions & 11 deletions speaker/voice_profile_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,13 @@ func (client VoiceProfileClient) Close() {
type CreateProfileOutcome struct {
common.OperationOutcome

profile *VoiceProfile
Profile *VoiceProfile
}

// Close releases the underlying resources
func (outcome CreateProfileOutcome) Close() {
if outcome.profile != nil {
outcome.profile.Close()
if outcome.Profile != nil {
outcome.Profile.Close()
}
}

Expand All @@ -79,13 +79,13 @@ func (client VoiceProfileClient) CreateProfileAsync(profileType common.VoiceProf
defer C.free(unsafe.Pointer(loc))
ret := uintptr(C.create_voice_profile(client.handle, (C.int)(profileType), loc, &profileHandle))
if ret != C.SPX_NOERROR {
outcome <- CreateProfileOutcome{profile: nil, OperationOutcome: common.OperationOutcome{common.NewCarbonError(ret)}}
outcome <- CreateProfileOutcome{Profile: nil, OperationOutcome: common.OperationOutcome{common.NewCarbonError(ret)}}
} else {
newProfile, err := newVoiceProfileFromHandle(handle2uintptr(profileHandle))
if err != nil {
outcome <- CreateProfileOutcome{profile: nil, OperationOutcome: common.OperationOutcome{err}}
outcome <- CreateProfileOutcome{Profile: nil, OperationOutcome: common.OperationOutcome{err}}
} else {
outcome <- CreateProfileOutcome{profile: newProfile, OperationOutcome: common.OperationOutcome{nil}}
outcome <- CreateProfileOutcome{Profile: newProfile, OperationOutcome: common.OperationOutcome{nil}}
}
}
}()
Expand Down Expand Up @@ -208,12 +208,12 @@ func (client VoiceProfileClient) RetrieveEnrollmentResultAsync(profile *VoicePro
type GetAllProfilesOutcome struct {
common.OperationOutcome

profiles []*VoiceProfile
Profiles []*VoiceProfile
}

// Close releases the underlying resources
func (outcome GetAllProfilesOutcome) Close() {
for _, profile := range outcome.profiles {
for _, profile := range outcome.Profiles {
if profile != nil {
profile.Close()
}
Expand All @@ -226,19 +226,19 @@ func (client VoiceProfileClient) GetAllProfilesAsync(profileType common.VoicePro
go func() {
rawProfileJson := C.get_profiles_json(client.handle, (C.int)(profileType))
if rawProfileJson == nil {
outcome <- GetAllProfilesOutcome{profiles: nil, OperationOutcome: common.OperationOutcome{common.NewCarbonError(uintptr(C.SPXERR_INVALID_ARG))}}
outcome <- GetAllProfilesOutcome{Profiles: nil, OperationOutcome: common.OperationOutcome{common.NewCarbonError(uintptr(C.SPXERR_INVALID_ARG))}}
} else {
goProfilesJson := C.GoString(rawProfileJson)
splitProfileIds := strings.Split(goProfilesJson, "|")
profileList := make([]*VoiceProfile, len(splitProfileIds))
for index, id := range splitProfileIds {
profile, err := NewVoiceProfileFromIdAndType(id, profileType)
if err != nil {
outcome <- GetAllProfilesOutcome{profiles: nil, OperationOutcome: common.OperationOutcome{err}}
outcome <- GetAllProfilesOutcome{Profiles: nil, OperationOutcome: common.OperationOutcome{err}}
}
profileList[index] = profile
}
outcome <- GetAllProfilesOutcome{profiles: profileList, OperationOutcome: common.OperationOutcome{nil}}
outcome <- GetAllProfilesOutcome{Profiles: profileList, OperationOutcome: common.OperationOutcome{nil}}
}
}()
return outcome
Expand Down
4 changes: 2 additions & 2 deletions speaker/voice_profile_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func GetNewVoiceProfileFromClient(t *testing.T, client *VoiceProfileClient, expe
t.Error("Got an error creating profile: ", outcome.Error.Error())
return nil
}
profile := outcome.profile
profile := outcome.Profile
id, err := profile.Id()
if err != nil {
t.Error("Unexpected error creating profile id: ", err)
Expand Down Expand Up @@ -360,7 +360,7 @@ func TestGetAllProfiles(t *testing.T) {
t.Error("Error getting all profiles: ", outcome.Error.Error())
return
}
profiles := outcome.profiles
profiles := outcome.Profiles
if len(profiles) < 1 {
t.Error("Unexpected error getting profiles, no profiles received")
}
Expand Down

0 comments on commit 6b3703a

Please sign in to comment.