Skip to content

Commit

Permalink
[NUI.AIAvatar] Refactoring AI Avatar. (#6526)
Browse files Browse the repository at this point in the history
Reorganized entire project structure for improved clarity and maintainability.
Introduced customizable interfaces for AI functionalities, allowing seamless integration of third-party modules.
Optimized existing code base for increased efficiency and reduced redundancy.

Co-authored-by: Angler <[email protected]>
  • Loading branch information
AnglerLee and Angler authored Jan 6, 2025
1 parent 3fb564c commit 19d0c1b
Show file tree
Hide file tree
Showing 132 changed files with 100,089 additions and 4,027 deletions.
2 changes: 0 additions & 2 deletions src/Tizen.AIAvatar/Tizen.AIAvatar.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="11.0.2" />
<ProjectReference Include="..\Tizen\Tizen.csproj" />
<ProjectReference Include="..\Tizen.Log\Tizen.Log.csproj" />
<ProjectReference Include="..\Tizen.Uix.Tts\Tizen.Uix.Tts.csproj" />
Expand All @@ -16,7 +15,6 @@
<ProjectReference Include="..\Tizen.MachineLearning.Inference\Tizen.MachineLearning.Inference.csproj" />
<ProjectReference Include="..\Tizen.Multimedia.AudioIO\Tizen.Multimedia.AudioIO.csproj" />
<ProjectReference Include="..\Tizen.Security\Tizen.Security.csproj" />
<ProjectReference Include="..\Tizen.Security.PrivacyPrivilegeManager\Tizen.Security.PrivacyPrivilegeManager.csproj" />
</ItemGroup>


Expand Down
82 changes: 82 additions & 0 deletions src/Tizen.AIAvatar/src/AIServices/BaseAIService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/*
* Copyright(c) 2024 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

using System;
using System.ComponentModel;

namespace Tizen.AIAvatar
{
/// <summary>
/// Abstract base class for AI services, providing common functionalities.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public abstract class BaseAIService : IAIService, IDisposable
{
/// <summary>
/// Gets the name of the AI service.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public abstract string ServiceName { get; }

/// <summary>
/// Gets the capabilities of the AI service.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public abstract ServiceCapabilities Capabilities { get; }

/// <summary>
/// Gets the service client manager responsible for managing client operations.
/// </summary>
protected ServiceClientManager ClientManager { get; }

/// <summary>
/// Gets the configuration settings for the AI service.
/// </summary>
protected AIServiceConfiguration Configuration { get; }

/// <summary>
/// Initializes a new instance of the <see cref="BaseAIService"/> class with the specified configuration.
/// </summary>
/// <param name="config">The configuration settings for the AI service.</param>
protected BaseAIService(AIServiceConfiguration config)
{
Configuration = config;
ClientManager = new ServiceClientManager(config);
}

/// <summary>
/// Releases all resources used by the AI service.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public virtual void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}

/// <summary>
/// Releases all resources used by the AI service.
/// </summary>
protected virtual void Dispose(bool disposing)
{
if (disposing && ClientManager != null)
{
ClientManager.Dispose();
}
}
}
}
185 changes: 185 additions & 0 deletions src/Tizen.AIAvatar/src/AIServices/Core/AIServiceData.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
/*
* Copyright(c) 2024 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

using System;
using System.Collections.Generic;
using System.ComponentModel;


namespace Tizen.AIAvatar
{
/// <summary>
/// Provides data for LLM response events.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public class llmResponseEventArgs : EventArgs
{
/// <summary>
/// Gets or sets the task ID associated with the LLM response.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public int TaskID { get; set; }

/// <summary>
/// Gets or sets the response text from the LLM.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public string Text { get; set; }

/// <summary>
/// Gets or sets the error message, if any, from the LLM response.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public string Error { get; set; }
}

/// <summary>
/// Provides data for TTS streaming events.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public class ttsStreamingEventArgs : EventArgs
{
/// <summary>
/// Gets or sets the audio data of the current chunk.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public byte[] AudioData { get; set; }

/// <summary>
/// Gets or sets the sample rate of the audio data.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public int SampleRate { get; set; }

/// <summary>
/// Gets or sets the text being converted to speech.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public string Text { get; set; }

/// <summary>
/// Gets or sets the voice used for the TTS conversion.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public string Voice { get; set; }

/// <summary>
/// Gets or sets the size of the current audio data chunk in bytes.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public int AudioBytes { get; set; }

/// <summary>
/// Gets or sets the total number of bytes for the audio data.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public int TotalBytes { get; set; }

/// <summary>
/// Gets or sets the number of bytes processed so far.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public int ProcessedBytes { get; set; }

/// <summary>
/// Gets or sets the progress percentage of the TTS processing.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public double ProgressPercentage { get; set; }

/// <summary>
/// Gets or sets the error message, if any, during the TTS process.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public string Error { get; set; }
}

/// <summary>
/// Provides data for STT streaming events.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public class sttStreamingEventArgs : EventArgs
{
/// <summary>
/// Gets or sets a value indicating whether the text is interim.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public bool Interim { get; set; }

/// <summary>
/// Gets or sets the transcribed text from the STT process.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public string Text { get; set; }

/// <summary>
/// Gets or sets the error message, if any, during the STT process.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public string Error { get; set; }
}

/// <summary>
/// Represents service endpoints for AI services.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public class ServiceEndpoints
{
/// <summary>
/// Gets or sets the endpoint for the LLM service.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public string LLMEndpoint { get; set; }

/// <summary>
/// Gets or sets the endpoint for the Text-to-Speech service.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public string TextToSpeechEndpoint { get; set; }

/// <summary>
/// Gets or sets the endpoint for the Speech-to-Text service.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public string SpeechToTextEndpoint { get; set; }
}

/// <summary>
/// Represents the configuration for an AI service.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public abstract class AIServiceConfiguration
{
/// <summary>
/// Gets or sets the API key for the AI service.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public string ApiKey { get; set; }

/// <summary>
/// Gets or sets the service endpoints.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public ServiceEndpoints Endpoints { get; set; }

/// <summary>
/// Gets or sets additional settings for the AI service.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public Dictionary<string, object> AdditionalSettings { get; set; } = new();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,51 +15,65 @@
*
*/

using System;
using System.ComponentModel;
using Tizen.Multimedia;

namespace Tizen.AIAvatar
{
/// <summary>
/// Provides the ability to audio
/// Defines the capabilities that an AI service can support.
/// </summary>
[Flags]
[EditorBrowsable(EditorBrowsableState.Never)]
internal class AudioOptions
public enum ServiceCapabilities
{
private int sampleRate;
private AudioChannel channel;
private AudioSampleType sampleType;
/// <summary>
/// No capabilities.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
None = 0,

/// <summary>
/// Capability for Text-to-Speech service.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
TextToSpeech = 1,

/// <summary>
/// Capability for Speech-to-Text service.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
SpeechToText = 2,

/// <summary>
/// Initializes a new instance of the AudioOptions class with the specified sample rate, channel, and sampleType.
/// Capability for Large Language Model service.
/// </summary>
/// <param name="sampleRate">the audio sample rate (8000 ~ 192000Hz)</param>
/// <param name="channel">the audio channel type.</param>
/// <param name="sampleType">the audio sample type.</param>
[EditorBrowsable(EditorBrowsableState.Never)]
public AudioOptions(int sampleRate, AudioChannel channel, AudioSampleType sampleType)
{
this.sampleRate = sampleRate;
this.channel = channel;
this.sampleType = sampleType;
}
LargeLanguageModel = 4,

/// <summary>
/// The audio sample rate (8000 ~ 192000Hz)
/// Capability for Vision-related service.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public int SampleRate { get => sampleRate; set => sampleRate = value; }
Vision = 8
}

/// <summary>
/// Represents a generic AI service interface.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public interface IAIService
{
/// <summary>
/// The audio channel type
/// Gets the name of the AI service.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public AudioChannel Channel { get => channel; set => channel = value; }
string ServiceName { get; }

/// <summary>
/// The audio sample type
/// Gets the capabilities of the AI service.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public AudioSampleType SampleType { get => sampleType; set => sampleType = value; }
ServiceCapabilities Capabilities { get; }
}
}
Loading

0 comments on commit 19d0c1b

Please sign in to comment.