From a2074a64112ae0d4996cba393efa8f8d0fcaefaa Mon Sep 17 00:00:00 2001 From: Yan Jin <601746725@qq.com> Date: Fri, 31 Mar 2023 17:52:51 -0700 Subject: [PATCH] 1. Update code convention config. 2. CORE-2014 Record button will gather all the audio chunk and sent to server. --- .editorconfig | 248 ++++++++++++++++++ .../Runtime/3DInteraction/BodyAnimation.cs | 2 +- .../Scripts/Runtime/Audio/AudioCapture.cs | 36 ++- .../Scripts/Runtime/Chat/RecordButton.cs | 4 +- .../Scripts/Runtime/Entities/InworldClient.cs | 26 +- .../Runtime/Entities/InworldController.cs | 47 +++- .../Scripts/Runtime/Util/InworldEnums.cs | 7 - 7 files changed, 331 insertions(+), 39 deletions(-) create mode 100644 .editorconfig diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 000000000..37ca01365 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,248 @@ + +[*] +charset = utf-8-bom +end_of_line = crlf +trim_trailing_whitespace = false +insert_final_newline = false +indent_style = space +indent_size = 4 + +# Microsoft .NET properties +csharp_preferred_modifier_order = public, protected, private, static, new, override, virtual, internal, sealed, abstract, async, extern, unsafe, volatile, readonly:suggestion +csharp_style_var_elsewhere = false:suggestion +csharp_style_var_for_built_in_types = false:suggestion +csharp_style_var_when_type_is_apparent = false:suggestion +dotnet_naming_rule.constants_rule.import_to_resharper = as_predefined +dotnet_naming_rule.constants_rule.resharper_style = k_ + aaBb, k_ + AaBb +dotnet_naming_rule.constants_rule.severity = warning +dotnet_naming_rule.constants_rule.style = k_lower_camel_case_style +dotnet_naming_rule.constants_rule.symbols = constants_symbols +dotnet_naming_rule.local_functions_rule.import_to_resharper = as_predefined +dotnet_naming_rule.local_functions_rule.resharper_style = AaBb, _ + AaBb +dotnet_naming_rule.local_functions_rule.severity = warning +dotnet_naming_rule.local_functions_rule.style = upper_camel_case_style +dotnet_naming_rule.local_functions_rule.symbols = local_functions_symbols +dotnet_naming_rule.private_constants_rule.import_to_resharper = as_predefined +dotnet_naming_rule.private_constants_rule.resharper_style = aaBb, AA_BB, k_ + AaBb +dotnet_naming_rule.private_constants_rule.severity = warning +dotnet_naming_rule.private_constants_rule.style = lower_camel_case_style +dotnet_naming_rule.private_constants_rule.symbols = private_constants_symbols +dotnet_naming_rule.private_instance_fields_rule.import_to_resharper = as_predefined +dotnet_naming_rule.private_instance_fields_rule.severity = warning +dotnet_naming_rule.private_instance_fields_rule.style = m_upper_camel_case_underscore_tolerant_style +dotnet_naming_rule.private_instance_fields_rule.symbols = private_instance_fields_symbols +dotnet_naming_rule.private_static_fields_rule.import_to_resharper = as_predefined +dotnet_naming_rule.private_static_fields_rule.resharper_style = __ + aaBb, s_ + AaBb, aaBb +dotnet_naming_rule.private_static_fields_rule.severity = warning +dotnet_naming_rule.private_static_fields_rule.style = lower_camel_case_style_1 +dotnet_naming_rule.private_static_fields_rule.symbols = private_static_fields_symbols +dotnet_naming_rule.private_static_readonly_rule.import_to_resharper = as_predefined +dotnet_naming_rule.private_static_readonly_rule.resharper_style = __ + aaBb, aaBb, s_ + AaBb +dotnet_naming_rule.private_static_readonly_rule.severity = warning +dotnet_naming_rule.private_static_readonly_rule.style = lower_camel_case_style_1 +dotnet_naming_rule.private_static_readonly_rule.symbols = private_static_readonly_symbols +dotnet_naming_rule.property_rule.import_to_resharper = as_predefined +dotnet_naming_rule.property_rule.resharper_style = AaBb, _ + AaBb +dotnet_naming_rule.property_rule.severity = warning +dotnet_naming_rule.property_rule.style = upper_camel_case_style +dotnet_naming_rule.property_rule.symbols = property_symbols +dotnet_naming_rule.public_fields_rule.import_to_resharper = as_predefined +dotnet_naming_rule.public_fields_rule.resharper_style = aaBb, m_ + AaBb +dotnet_naming_rule.public_fields_rule.severity = warning +dotnet_naming_rule.public_fields_rule.style = lower_camel_case_style +dotnet_naming_rule.public_fields_rule.symbols = public_fields_symbols +dotnet_naming_rule.static_readonly_rule.import_to_resharper = as_predefined +dotnet_naming_rule.static_readonly_rule.severity = warning +dotnet_naming_rule.static_readonly_rule.style = upper_camel_case_style +dotnet_naming_rule.static_readonly_rule.symbols = static_readonly_symbols +dotnet_naming_rule.unity_serialized_field_rule.import_to_resharper = True +dotnet_naming_rule.unity_serialized_field_rule.resharper_description = Unity serialized field +dotnet_naming_rule.unity_serialized_field_rule.resharper_guid = 5f0fdb63-c892-4d2c-9324-15c80b22a7ef +dotnet_naming_rule.unity_serialized_field_rule.severity = none +dotnet_naming_rule.unity_serialized_field_rule.style = m_upper_camel_case_style +dotnet_naming_rule.unity_serialized_field_rule.symbols = unity_serialized_field_symbols +dotnet_naming_style.k_lower_camel_case_style.capitalization = camel_case +dotnet_naming_style.k_lower_camel_case_style.required_prefix = k_ +dotnet_naming_style.lower_camel_case_style.capitalization = camel_case +dotnet_naming_style.lower_camel_case_style_1.capitalization = camel_case +dotnet_naming_style.lower_camel_case_style_1.required_prefix = __ +dotnet_naming_style.m_upper_camel_case_style.capitalization = pascal_case +dotnet_naming_style.m_upper_camel_case_style.required_prefix = m_ +dotnet_naming_style.m_upper_camel_case_underscore_tolerant_style.capitalization = pascal_case +dotnet_naming_style.m_upper_camel_case_underscore_tolerant_style.required_prefix = m_ +dotnet_naming_style.m_upper_camel_case_underscore_tolerant_style.word_separator = _ +dotnet_naming_style.upper_camel_case_style.capitalization = pascal_case +dotnet_naming_symbols.constants_symbols.applicable_accessibilities = public,internal,protected,protected_internal,private_protected +dotnet_naming_symbols.constants_symbols.applicable_kinds = field +dotnet_naming_symbols.constants_symbols.required_modifiers = const +dotnet_naming_symbols.local_functions_symbols.applicable_accessibilities = * +dotnet_naming_symbols.local_functions_symbols.applicable_kinds = local_function +dotnet_naming_symbols.private_constants_symbols.applicable_accessibilities = private +dotnet_naming_symbols.private_constants_symbols.applicable_kinds = field +dotnet_naming_symbols.private_constants_symbols.required_modifiers = const +dotnet_naming_symbols.private_instance_fields_symbols.applicable_accessibilities = private +dotnet_naming_symbols.private_instance_fields_symbols.applicable_kinds = field +dotnet_naming_symbols.private_static_fields_symbols.applicable_accessibilities = private +dotnet_naming_symbols.private_static_fields_symbols.applicable_kinds = field +dotnet_naming_symbols.private_static_fields_symbols.required_modifiers = static +dotnet_naming_symbols.private_static_readonly_symbols.applicable_accessibilities = private +dotnet_naming_symbols.private_static_readonly_symbols.applicable_kinds = field +dotnet_naming_symbols.private_static_readonly_symbols.required_modifiers = static,readonly +dotnet_naming_symbols.property_symbols.applicable_accessibilities = * +dotnet_naming_symbols.property_symbols.applicable_kinds = property +dotnet_naming_symbols.public_fields_symbols.applicable_accessibilities = public,internal,protected,protected_internal,private_protected +dotnet_naming_symbols.public_fields_symbols.applicable_kinds = field +dotnet_naming_symbols.static_readonly_symbols.applicable_accessibilities = public,internal,protected,protected_internal,private_protected +dotnet_naming_symbols.static_readonly_symbols.applicable_kinds = field +dotnet_naming_symbols.static_readonly_symbols.required_modifiers = static,readonly +dotnet_naming_symbols.unity_serialized_field_symbols.applicable_accessibilities = * +dotnet_naming_symbols.unity_serialized_field_symbols.applicable_kinds = +dotnet_naming_symbols.unity_serialized_field_symbols.resharper_applicable_kinds = unity_serialised_field +dotnet_naming_symbols.unity_serialized_field_symbols.resharper_required_modifiers = instance +dotnet_sort_system_directives_first = false +dotnet_style_parentheses_in_arithmetic_binary_operators = always_for_clarity:none +dotnet_style_parentheses_in_other_binary_operators = always_for_clarity:none +dotnet_style_parentheses_in_relational_binary_operators = never_if_unnecessary:none +dotnet_style_predefined_type_for_locals_parameters_members = true:suggestion +dotnet_style_predefined_type_for_member_access = true:suggestion +dotnet_style_qualification_for_event = false:suggestion +dotnet_style_qualification_for_field = false:suggestion +dotnet_style_qualification_for_method = false:suggestion +dotnet_style_qualification_for_property = false:suggestion +dotnet_style_require_accessibility_modifiers = never:suggestion + +# ReSharper properties +resharper_align_linq_query = true +resharper_align_multiline_argument = true +resharper_align_multiline_binary_patterns = true +resharper_align_multiline_calls_chain = true +resharper_align_multiline_extends_list = true +resharper_align_multiline_for_stmt = true +resharper_align_multiline_parameter = true +resharper_align_multiline_statement_conditions = false +resharper_align_multiple_declaration = true +resharper_align_multline_type_parameter_constrains = true +resharper_align_multline_type_parameter_list = true +resharper_align_tuple_components = true +resharper_autodetect_indent_settings = true +resharper_blank_lines_after_block_statements = 0 +resharper_blank_lines_after_start_comment = 0 +resharper_blank_lines_after_using_list = 0 +resharper_blank_lines_around_auto_property = 0 +resharper_blank_lines_around_property = 0 +resharper_blank_lines_around_single_line_type = 0 +resharper_braces_for_for = required_for_multiline +resharper_braces_for_ifelse = not_required +resharper_braces_for_while = required_for_multiline_statement +resharper_braces_redundant = false +resharper_continuous_line_indent = none +resharper_cpp_indent_style = tab +resharper_cpp_int_align_comments = true +resharper_cpp_max_line_length = 153 +resharper_cpp_space_after_keywords_in_control_flow_statements = false +resharper_cpp_type_declaration_braces = end_of_line +resharper_csharp_blank_lines_around_field = 0 +resharper_csharp_blank_lines_around_invocable = 0 +resharper_csharp_blank_lines_around_namespace = 0 +resharper_csharp_blank_lines_around_type = 0 +resharper_csharp_blank_lines_inside_region = 0 +resharper_csharp_empty_block_style = together_same_line +resharper_csharp_indent_statement_pars = outside +resharper_csharp_insert_final_newline = true +resharper_csharp_keep_blank_lines_in_declarations = 100 +resharper_csharp_max_line_length = 812 +resharper_csharp_naming_rule.enum_member = AaBb_AaBb, AA_BB +resharper_csharp_outdent_commas = true +resharper_csharp_wrap_after_declaration_lpar = true +resharper_csharp_wrap_after_invocation_lpar = true +resharper_csharp_wrap_before_declaration_lpar = true +resharper_csharp_wrap_before_declaration_rpar = true +resharper_csharp_wrap_before_invocation_lpar = true +resharper_csharp_wrap_before_invocation_rpar = true +resharper_csharp_wrap_extends_list_style = chop_if_long +resharper_csharp_wrap_multiple_declaration_style = wrap_if_long +resharper_csharp_wrap_ternary_expr_style = wrap_if_long +resharper_indent_nested_fixed_stmt = true +resharper_indent_nested_foreach_stmt = true +resharper_indent_nested_for_stmt = true +resharper_indent_nested_lock_stmt = true +resharper_indent_nested_usings_stmt = true +resharper_indent_nested_while_stmt = true +resharper_indent_preprocessor_directives = normal +resharper_indent_preprocessor_if = do_not_change +resharper_indent_preprocessor_region = do_not_change +resharper_instance_members_qualify_declared_in = +resharper_int_align_declaration_names = true +resharper_keep_existing_attribute_arrangement = true +resharper_keep_existing_embedded_arrangement = false +resharper_keep_existing_enum_arrangement = true +resharper_keep_existing_expr_member_arrangement = false +resharper_keep_existing_initializer_arrangement = false +resharper_keep_existing_switch_expression_arrangement = false +resharper_max_attribute_length_for_same_line = 10000 +resharper_nested_ternary_style = simple_wrap +resharper_new_line_before_while = true +resharper_object_creation_when_type_evident = explicitly_typed +resharper_parentheses_non_obvious_operations = none, conditional_and, bitwise, bitwise_inclusive_or, bitwise_exclusive_or, shift, bitwise_and +resharper_parentheses_redundancy_style = remove +resharper_parentheses_same_type_operations = true +resharper_place_attribute_on_same_line = if_owner_is_single_line +resharper_place_expr_accessor_on_single_line = true +resharper_place_expr_method_on_single_line = true +resharper_place_expr_property_on_single_line = true +resharper_place_simple_anonymousmethod_on_single_line = false +resharper_place_simple_embedded_statement_on_same_line = false +resharper_place_simple_enum_on_single_line = true +resharper_remove_blank_lines_near_braces_in_code = false +resharper_simple_embedded_statement_style = on_single_line +resharper_space_between_attribute_sections = false +resharper_space_within_empty_braces = false +resharper_space_within_single_line_array_initializer_braces = false +resharper_toplevel_function_definition_return_type_style = on_single_line +resharper_use_indent_from_vs = false +resharper_wrap_after_expression_lbrace = false +resharper_wrap_array_initializer_style = chop_if_long +resharper_wrap_before_binary_pattern_op = false +resharper_wrap_before_expression_rbrace = false +resharper_wrap_chained_binary_expressions = chop_if_long +resharper_wrap_chained_binary_patterns = chop_if_long +resharper_wrap_for_stmt_header_style = wrap_if_long +resharper_wrap_object_and_collection_initializer_style = chop_always +resharper_wrap_switch_expression = wrap_if_long + +# ReSharper inspection severities +resharper_arrange_redundant_parentheses_highlighting = hint +resharper_arrange_this_qualifier_highlighting = hint +resharper_arrange_type_member_modifiers_highlighting = hint +resharper_arrange_type_modifiers_highlighting = hint +resharper_built_in_type_reference_style_for_member_access_highlighting = hint +resharper_built_in_type_reference_style_highlighting = hint +resharper_redundant_base_qualifier_highlighting = warning +resharper_suggest_var_or_type_built_in_types_highlighting = hint +resharper_suggest_var_or_type_elsewhere_highlighting = hint +resharper_suggest_var_or_type_simple_types_highlighting = hint +resharper_web_config_module_not_resolved_highlighting = warning +resharper_web_config_type_not_resolved_highlighting = warning +resharper_web_config_wrong_module_highlighting = warning + +[{*.har,*.inputactions,*.jsb2,*.jsb3,*.json,.babelrc,.eslintrc,.stylelintrc,bowerrc,jest.config}] +indent_style = space +indent_size = 2 + +[{*.yaml,*.yml}] +indent_style = space +indent_size = 2 + +[*.asmdef] +indent_style = space +indent_size = 2 + +[*.{c,c++,cc,cginc,compute,cp,cpp,cu,cuh,cxx,fx,fxh,h,hh,hlsl,hlsli,hlslinc,hpp,hxx,inc,inl,ino,ipp,mpp,mq4,mq5,mqh,tpp,usf,ush}] +indent_style = tab +indent_size = tab +tab_width = 4 + +[*.{appxmanifest,asax,ascx,aspx,axaml,build,cs,cshtml,dtd,fs,fsi,fsscript,fsx,master,ml,mli,nuspec,paml,razor,resw,resx,shader,skin,vb,xaml,xamlx,xoml,xsd}] +indent_style = space +indent_size = 4 +tab_width = 4 diff --git a/Assets/Inworld.AI/Scripts/Runtime/3DInteraction/BodyAnimation.cs b/Assets/Inworld.AI/Scripts/Runtime/3DInteraction/BodyAnimation.cs index adf9fcffd..77c39878c 100644 --- a/Assets/Inworld.AI/Scripts/Runtime/3DInteraction/BodyAnimation.cs +++ b/Assets/Inworld.AI/Scripts/Runtime/3DInteraction/BodyAnimation.cs @@ -189,7 +189,7 @@ void OnCharacterChanged(InworldCharacter oldCharacter, InworldCharacter newChara } else if (newCharacter == Character) { - Animator.enabled = false; + Animator.enabled = true; HandleMainStatus(AnimMainStatus.Hello); } } diff --git a/Assets/Inworld.AI/Scripts/Runtime/Audio/AudioCapture.cs b/Assets/Inworld.AI/Scripts/Runtime/Audio/AudioCapture.cs index 512133f64..f31bef19c 100644 --- a/Assets/Inworld.AI/Scripts/Runtime/Audio/AudioCapture.cs +++ b/Assets/Inworld.AI/Scripts/Runtime/Audio/AudioCapture.cs @@ -5,8 +5,10 @@ * that can be found in the LICENSE.md file or at https://www.inworld.ai/sdk-license *************************************************************************************************/ using Google.Protobuf; +using Inworld.Util; using UnityEngine; using UnityEngine.Events; +using System.Collections.Generic; namespace Inworld { @@ -18,8 +20,11 @@ public class AudioCapture : MonoBehaviour { public UnityEvent OnRecordingStart; public UnityEvent OnRecordingEnd; + public bool IsCapturing { get; set; } [SerializeField] int m_AudioRate = 16000; [SerializeField] int m_BufferSeconds = 1; + + readonly List m_AudioToPush = new List(); // Size of audioclip used to collect information, need to be big enough to keep up with collect. int m_BufferSize; const int k_SizeofInt16 = sizeof(short); @@ -29,19 +34,23 @@ public class AudioCapture : MonoBehaviour float m_CDCounter; // Last known position in AudioClip buffer. int m_LastPosition; + bool m_AutoPush; - // public bool IsEnabled { get; set; } - public bool IsCapturing { get; set; } - public void StartRecording() + public void StartRecording(bool autoPush = true) { m_Recording = Microphone.Start(null, true, m_BufferSeconds, m_AudioRate); m_LastPosition = Microphone.GetPosition(null); + m_AudioToPush.Clear(); + IsCapturing = true; + m_AutoPush = autoPush; OnRecordingStart.Invoke(); } public void StopRecording() { Microphone.End(null); + m_AudioToPush.Clear(); IsCapturing = false; + m_AutoPush = true; OnRecordingEnd.Invoke(); } void Awake() @@ -50,16 +59,12 @@ void Awake() m_ByteBuffer = new byte[m_BufferSize * 1 * k_SizeofInt16]; m_FloatBuffer = new float[m_BufferSize * 1]; } - void Start() - { - StartRecording(); - } void Update() { - if (!Microphone.IsRecording(null)) - StartRecording(); if (!IsCapturing) return; + if (!Microphone.IsRecording(null)) + StartRecording(); if (m_CDCounter <= 0) { m_CDCounter = 0.1f; @@ -83,7 +88,18 @@ void _Collect() return; m_LastPosition = nPosition % m_BufferSize; WavUtility.ConvertAudioClipDataToInt16ByteArray(m_FloatBuffer, nSize * m_Recording.channels, m_ByteBuffer); - InworldController.Instance.SendAudio(ByteString.CopyFrom(m_ByteBuffer, 0, nSize * m_Recording.channels * k_SizeofInt16)); + ByteString audioData = ByteString.CopyFrom(m_ByteBuffer, 0, nSize * m_Recording.channels * k_SizeofInt16); + if (m_AutoPush) + InworldController.Instance.SendAudio(audioData); + else + m_AudioToPush.Add(audioData); + } + public void PushAudio() + { + foreach (ByteString audioData in m_AudioToPush) + { + InworldController.Instance.SendAudio(audioData); + } } } } diff --git a/Assets/Inworld.AI/Scripts/Runtime/Chat/RecordButton.cs b/Assets/Inworld.AI/Scripts/Runtime/Chat/RecordButton.cs index 93c6fa10d..a950e631e 100644 --- a/Assets/Inworld.AI/Scripts/Runtime/Chat/RecordButton.cs +++ b/Assets/Inworld.AI/Scripts/Runtime/Chat/RecordButton.cs @@ -26,12 +26,12 @@ void OnDisable() } public void OnPointerDown(PointerEventData eventData) { - InworldController.IsCapturing = true; + InworldController.Instance.StartRecording(false); } public void OnPointerUp(PointerEventData eventData) { - InworldController.IsCapturing = false; + InworldController.Instance.PushAudio(); } } } diff --git a/Assets/Inworld.AI/Scripts/Runtime/Entities/InworldClient.cs b/Assets/Inworld.AI/Scripts/Runtime/Entities/InworldClient.cs index 8b1e056c5..13a6de50c 100644 --- a/Assets/Inworld.AI/Scripts/Runtime/Entities/InworldClient.cs +++ b/Assets/Inworld.AI/Scripts/Runtime/Entities/InworldClient.cs @@ -68,7 +68,7 @@ internal InworldClient() #region Properties internal ConcurrentQueue Errors { get; } = new ConcurrentQueue(); - internal bool IsInteracting { get; private set; } + internal bool SessionStarted { get; private set; } internal bool HasInit => !m_InworldAuth.IsExpired; internal string SessionID => m_InworldAuth?.SessionID ?? ""; internal string LastState { get; set; } @@ -146,7 +146,7 @@ internal async Task LoadScene(string sceneName) internal void StartAudio(Routing routing) { InworldAI.Log("Start Audio Event"); - if (IsInteracting) + if (SessionStarted) m_CurrentConnection?.outgoingEventsQueue.Enqueue ( new GrpcPacket @@ -164,7 +164,7 @@ internal void StartAudio(Routing routing) // Marks session end. internal void EndAudio(Routing routing) { - if (IsInteracting) + if (SessionStarted) m_CurrentConnection?.outgoingEventsQueue.Enqueue ( new GrpcPacket @@ -182,7 +182,7 @@ internal void EndAudio(Routing routing) // Sends audio chunk to server. internal void SendAudio(AudioChunk audioEvent) { - if (IsInteracting) + if (SessionStarted) m_CurrentConnection?.outgoingEventsQueue.Enqueue(audioEvent.ToGrpc()); } internal bool GetAudioChunk(out AudioChunk chunk) @@ -205,7 +205,7 @@ internal bool GetAnimationChunk(out AnimationChunk chunk) } internal void SendEvent(InworldPacket e) { - if (IsInteracting) + if (SessionStarted) m_CurrentConnection?.outgoingEventsQueue.Enqueue(e.ToGrpc()); } internal bool GetIncomingEvent(out InworldPacket incomingEvent) @@ -227,7 +227,7 @@ internal async Task StartSession() Connection connection = new Connection(); m_CurrentConnection = connection; - IsInteracting = true; + SessionStarted = true; try { using (m_StreamingCall = m_WorldEngineClient.Session(m_Header)) @@ -237,7 +237,7 @@ internal async Task StartSession() ( async () => { - while (IsInteracting) + while (SessionStarted) { bool next; try @@ -273,14 +273,14 @@ internal async Task StartSession() ( async () => { - while (IsInteracting) + while (SessionStarted) { Task.Delay(100).Wait(); // Sending all outgoing events. GrpcPacket e; while (connection.outgoingEventsQueue.TryDequeue(out e)) { - if (IsInteracting) + if (SessionStarted) { await m_StreamingCall.RequestStream.WriteAsync(e); } @@ -293,12 +293,12 @@ internal async Task StartSession() } catch (Exception e) { - IsInteracting = false; + SessionStarted = false; Errors.Enqueue(e); } finally { - IsInteracting = false; + SessionStarted = false; } } internal TextEvent ResolvePreviousPackets(GrpcPacket response) => response.Text != null ? new TextEvent(response) : null; @@ -352,10 +352,10 @@ void _ResolveGRPCPackets(GrpcPacket response) } internal async Task EndSession() { - if (IsInteracting) + if (SessionStarted) { m_CurrentConnection = null; - IsInteracting = false; + SessionStarted = false; await m_StreamingCall.RequestStream.CompleteAsync(); m_StreamingCall.Dispose(); } diff --git a/Assets/Inworld.AI/Scripts/Runtime/Entities/InworldController.cs b/Assets/Inworld.AI/Scripts/Runtime/Entities/InworldController.cs index 9d6ab39b8..8044e8dc1 100644 --- a/Assets/Inworld.AI/Scripts/Runtime/Entities/InworldController.cs +++ b/Assets/Inworld.AI/Scripts/Runtime/Entities/InworldController.cs @@ -103,8 +103,12 @@ public static bool IsCapturing if (!Instance) return; AudioCapture capture = Instance.m_Capture; - if (capture) - capture.IsCapturing = value; + if (!capture) + return; + if (value) + capture.StartRecording(); + else + capture.StopRecording(); } } /// @@ -255,7 +259,7 @@ void _StartAudioCapture(string characterID) { m_CurrentRecordingID = characterID; m_Client.StartAudio(Routing.FromPlayerToAgent(characterID)); - m_Capture.IsCapturing = true; //Isenabled + m_Capture.StartRecording(); InworldAI.Log("Capture started."); } void _BindCharacterFromServer @@ -336,7 +340,7 @@ IEnumerator InteractionCoroutine() _GetIncomingEvents(); _SelectCharacter(); // Client stopped. - if (!m_Client.IsInteracting && !m_Client.Errors.IsEmpty) + if (!m_Client.SessionStarted && !m_Client.Errors.IsEmpty) { while (m_Client.Errors.TryDequeue(out Exception exception)) { @@ -401,7 +405,38 @@ public void Init() m_Client.RuntimeEvent += OnRuntimeEvents; m_Client.GetAppAuth(); } - + /// + /// Start Recording + /// + /// If autopush, whenever you finished talking, the data would be sent to server. + /// by default is true + public void StartRecording(bool autoPush = true) + { + AudioCapture capture = m_Capture; + if (!capture) + return; + capture.StartRecording(autoPush); + } + /// + /// Stop Recording + /// + public void StopRecording() + { + AudioCapture capture = m_Capture; + if (!capture) + return; + capture.StopRecording(); + } + /// + /// Manually Push Audio. Called when autoPush of AudioCapture is false + /// + public void PushAudio() + { + AudioCapture capture = m_Capture; + if (!capture) + return; + capture.PushAudio(); + } /// /// Start session with target InworldCharacter directly /// If success, it'll create a default InworldScene of that character, @@ -578,7 +613,7 @@ public void EndAudioCapture(string characterID = null) { m_Client.EndAudio(Routing.FromPlayerToAgent(m_CurrentRecordingID)); if (m_Capture) - m_Capture.IsCapturing = false; //IsEnabled + m_Capture.IsCapturing = false; m_CurrentRecordingID = null; InworldAI.Log("Capture ended."); } diff --git a/Assets/Inworld.AI/Scripts/Runtime/Util/InworldEnums.cs b/Assets/Inworld.AI/Scripts/Runtime/Util/InworldEnums.cs index ff6bd05ef..b6451dab1 100644 --- a/Assets/Inworld.AI/Scripts/Runtime/Util/InworldEnums.cs +++ b/Assets/Inworld.AI/Scripts/Runtime/Util/InworldEnums.cs @@ -66,13 +66,6 @@ public enum ControllerStates Error // Some error occured. } - public enum InworldSceneStatus - { - Unknown, - CharacterInit, - LoadSceneFailed - } - public enum AnimMainStatus { Neutral = 0,