Azure-Samples / cognitive-services-speech-sdk

Sample code for the Microsoft Cognitive Services Speech SDK
MIT License
2.96k stars 1.86k forks source link

How to speech to speech in Swift #1889

Closed TheWebartist closed 1 year ago

TheWebartist commented 1 year ago

Hi,

I develop an app in Swift (yes I know 🥲 ) and I want to use Synthesis for translate speech to speech.

I haven't found any sample for this scenario and I'm very confused when I search in addEvent

If I can easyly use text from recoginition result, I don't see how to access to synthesis ?

We have a text property, but no audio, synthesizedAudio.

I haven't found any addSynthesizing or addSynthesized event (we have a Synthesizing event in C# SDK)

reco.addRecognizedEventHandler() {reco, evt in
    print("Final rognition result: \(evt.result.text ?? "(no result)")")
    self.sendEvent(withName: "onSpeechRecognition", body: evt.result.text)
}

Have you some information to help A .NET lover lost in Swift (I cannot use MAUI for this app 😪 )

Swift #Synthesizing

TheWebartist commented 1 year ago

Ok I'have found this and I will search how to play it in a native player :

synthetizer.addSynthesizingEventHandler(){ synthetizer, evt in
    print("Final recognition Synthetize result: \(evt.result.audioData)")
   }

But I think that a sample that uses Synthetizing can be usefull for Swift developers (objective-c is out of date 😄 )

chschrae commented 1 year ago

Hi @TheWebartist

Thanks for asking! The Swift should support the translation API just as the other languages, but we do not have full samples for it.

One requirement for synthesis on translationRecognizer is that you set the desired voice (this is from the c# sample)

            // Optional: If in addition to the translated text you also need the synthesized audio, then provide the voice name
            var germanVoice = "de-DE-AmalaNeural";
            config.VoiceName = germanVoice;

If that does not work, you could absolutely use the synthesizer object to have a little more control over when it happens.

I hope this helps. Feel free to reopen the issue if you are still having any trouble.