Skip to content

Commit

Permalink
1. Update code convention config. 2. CORE-2014 Record button will gat…
Browse files Browse the repository at this point in the history
…her all the audio chunk and sent to server.
  • Loading branch information
Juniverse committed Apr 1, 2023
1 parent ce3fe15 commit a2074a6
Show file tree
Hide file tree
Showing 7 changed files with 331 additions and 39 deletions.
248 changes: 248 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ void OnCharacterChanged(InworldCharacter oldCharacter, InworldCharacter newChara
}
else if (newCharacter == Character)
{
Animator.enabled = false;
Animator.enabled = true;
HandleMainStatus(AnimMainStatus.Hello);
}
}
Expand Down
36 changes: 26 additions & 10 deletions Assets/Inworld.AI/Scripts/Runtime/Audio/AudioCapture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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<ByteString> m_AudioToPush = new List<ByteString>();
// 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);
Expand All @@ -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()
Expand All @@ -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;
Expand All @@ -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);
}
}
}
}
4 changes: 2 additions & 2 deletions Assets/Inworld.AI/Scripts/Runtime/Chat/RecordButton.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
}
Loading

0 comments on commit a2074a6

Please sign in to comment.