Working with Audio in Semantic Kernel Python

Working with Audio in Semantic Kernel Python

We are happy to announce the arrival of audio assist in Semantic Kernel Python. This new audio performance will allow you to create extra interactive and accessible consumer experiences. In this weblog submit, I’ll element the brand new interface, the prevailing connectors, and supply samples. Please proceed studying for extra info.

Audio-to-Text

The first characteristic we’re introducing is the flexibility to transcribe audio into textual content. The foundational class for this characteristic is AudioToTextClientBase, which incorporates two public strategies: get_text_contents and get_text_content. The former returns a listing of doable transcriptions based mostly on the quantity requested, whereas the latter returns a single transcription. The transcriptions are returned as TextContent material objects. Notably, get_text_content internally calls get_text_contents and easily returns the primary transcription from the checklist.
As of the publication of this weblog submit, the obtainable providers embody OpenAIAudioToText and AzureAudioToText, permitting you to make the most of both your OpenAI endpoints or Azure deployments.

AudioContent material

With the introduction of audio assist, we’re additionally introducing a brand new content material sort generally known as AudioContent material. Instances of the AudioContent material class ought to encapsulate both the binary knowledge or the URI pointing to the placement of the audio knowledge. Additionally, this class provides a handy methodology that permits you to create an AudioContent material object immediately from a file:

AudioContent material.from_audio_file(path=PATH_TO_AUDIO_FILE)

Audio-to-Text Example Using Azure OpenAI

Please be certain that Semantic Kernel is up to date to the newest model. To course of audio enter, the next elements are required:

  1. A speech-to-text mannequin, akin to whisper-1
  2. An audio enter system

To start, create the service with the next code:

from semantic_kernel.connectors.ai.open_ai.providers.azure_audio_to_text import AzureAudioToText


audio_to_text_service = AzureAudioToText(api_key="...", deployment_name="...", endpoint="...")

Next, you have to to create the audio content material that will likely be transcribed into textual content:

from semantic_kernel.contents.audio_content import AudioContent material


audio_content = AudioContent material.from_audio_file(path="...")

Finally, you possibly can invoke the service to get the transcription:

user_input = await audio_to_text_service.get_text_content(audio_content)
print(user_input)

To additional create an interactive chat app that takes audio as enter, please learn this weblog submit or see the pattern app in our GitHub repository.

Text-To-Audio

The second characteristic we’re introducing is the flexibility to create audio from textual content. The foundational class for this characteristic is TextToAudioClientBase, which incorporates two public strategies: get_audio_contents and get_audio_content. Similar to AudioToTextCientBase,the former returns a listing of doable audio generations based mostly on the quantity requested, whereas the latter returns a single audio technology. The audio generations are returned as AudioContent material objects that comprise the audio knowledge. To take heed to the audio knowledge, AudioContent material present one other handy methodology to avoid wasting the info to an audio file:

audio_content = ...
audio_content.write_to_file(path=PATH_TO_FILE)

As of the publication of this weblog submit, the obtainable providers embody OpenAIAudioToText and AzureAudioToText, permitting you to make the most of both your OpenAI endpoints or Azure deployments.

Text-to-Audio Example Using Azure OpenAI

Please be certain that Semantic Kernel is up to date to the newest model. To course of audio output, the next elements are required:

  1. A text-to-speech mannequin, akin to tts
  2. An audio output system

To start, create the service with the next code:

from semantic_kernel.connectors.ai.open_ai.providers.azure_text_to_audio import AzureTextToAudio


text_to_audio_service = AzureTextToAudio(api_key="...", deployment_name="...", endpoint="...")

Next, you possibly can invoke the service to get an audio technology:

audio_content = await text_to_audio_service.get_audio_content("Hello World!")

Finally, save the audio content material in an effort to take heed to it along with your favourite participant:

audio_content.write_to_file(path="...")

To additional create an interactive chat app that output audio, please learn extra on this weblog submit or see the pattern app in our GitHub repository.

HI-FI News

through Microsoft for Developers https://ift.tt/bv2K5Zy

November 15, 2024 at 05:51PM