private void LoadProfile(string key) { if ( //AudioWordDetection.LoadProfiles(new FileInfo(key)) //|| AudioWordDetection.LoadProfilesPrefs(key)) //) { for (int wordIndex = 0; wordIndex < AudioWordDetection.Words.Count; ++wordIndex) { WordDetails details = AudioWordDetection.Words[wordIndex]; if (null != details.Wave && details.Wave.Length > 0) { if (null == details.Audio) { details.Audio = AudioClip.Create(string.Empty, details.Wave.Length, 1, Mic.SampleRate, false, false); } details.Audio.SetData(details.Wave, 0); audio.loop = false; audio.mute = false; } SetupWordProfile(details, false); } } }
public void LoadWord(BinaryReader br, WordDetails details) { details.Label = br.ReadString(); int channels = br.ReadInt32(); int frequency = br.ReadInt32(); int size = br.ReadInt32(); details.Wave = new float[size]; for (int index = 0; index < size; ++index) { details.Wave[index] = br.ReadSingle(); } int halfSize = size / 2; details.SpectrumImag = new float[halfSize]; details.SpectrumReal = new float[halfSize]; Mic.GetSpectrumData(details.Wave, details.SpectrumReal, details.SpectrumImag, FFTWindow.Rectangular); if (null == details.Audio) { details.Audio = AudioClip.Create(Guid.NewGuid().ToString(), size, channels, frequency, false); } if (null != details.Audio && null != details.Wave) { details.Audio.SetData(details.Wave, 0); } }
/// <summary> /// Calling LanguageService depending on what mode we are using (translation or synonym). /// </summary> private async void TranslateAsync() { LanguageService languageService = new LanguageService(); if (SelectedItemfuncs == "translate") { Translate resu = await service.GetTranslation(Expression, SelectedItem + '-' + SelectedItemto); if (resu == null) { Result = "No query result"; } else { Result = resu.GetTranslations(); } } else if (SelectedItemfuncs == "synonym") { WordDetails wd = await service.GetSynonym(Expression, SelectedItem); Result = wd.ToString(); } else { Result = "Choose a Magic Mode!"; } if (Result != "No query result" && Result != "Choose a Magic Mode!") { string[] add = Result.Split(','); history.Insert(0, SelectedItemfuncs + ": " + Expression + " to " + add[0]); } }
void SaveProfile(WordDetails details) { string path = string.Format("Assets/{0}_{1}.profile", GetType().Name, details.Label); if (!string.IsNullOrEmpty(path)) { try { using ( FileStream fs = File.Open(path, FileMode.OpenOrCreate, FileAccess.Write, FileShare.ReadWrite) ) { using (BinaryWriter bw = new BinaryWriter(fs)) { AudioWordDetection.SaveWord(bw, details); //Debug.Log(string.Format("Save profile: {0}", details.Label)); } } } catch (Exception) { Debug.LogError(string.Format("Failed to save profile: {0}", details.Label)); } } }
public void SaveProfiles(BinaryWriter bw) { int count = 0; for (int index = 0; index < Words.Count; ++index) { WordDetails details = Words[index]; if (null == details) { continue; } ++count; } bw.Write(count); for (int index = 0; index < Words.Count; ++index) { WordDetails details = Words[index]; if (null == details) { continue; } SaveWord(bw, details); } }
/// <summary> /// Getting synonyms of given expression in the chosen language. Using Thesaurus API. /// </summary> /// <param name="expression"></param> /// <param name="lango"></param> /// <returns></returns> public async Task <WordDetails> GetSynonym(string expression, string lango) { string api = "88J1LrO1Af77ov1huMfQ"; string url = "http://thesaurus.altervista.org/thesaurus/v1?word=" + expression + "&language=" + lango + "&key=" + api + "&output=json"; string json = await GetAsync(url); WordDetails word = JsonConvert.DeserializeObject <WordDetails>(json); return(word); }
private string GetPreviosWord(WordDetails wordDetails, string text) { //if is first word we don't have prev word if (wordDetails.Position.Equals(0)) { return(string.Empty); } var firstPartOfString = text.Substring(0, wordDetails.Position).TrimEnd(); return(firstPartOfString.Substring(firstPartOfString.LastIndexOf(" ", StringComparison.Ordinal))); }
/// <summary> /// Initialize the example /// </summary> protected override void Start() { if (null == AudioWordDetection || null == Mic) { Debug.LogError("Missing meta references"); return; } WordDetails wordNoise = new WordDetails() { Label = WORD_NOISE }; // prepopulate words AudioWordDetection.Words.Add(wordNoise); AudioWordDetection.Words.Add(new WordDetails() { Label = WORD_PUSH_TO_TALK }); AudioWordDetection.Words.Add(new WordDetails() { Label = WORD_RESET }); AudioWordDetection.Words.Add(new WordDetails() { Label = WORD_GROW }); AudioWordDetection.Words.Add(new WordDetails() { Label = WORD_SHRINK }); AudioWordDetection.Words.Add(new WordDetails() { Label = WORD_LEFT }); AudioWordDetection.Words.Add(new WordDetails() { Label = WORD_RIGHT }); AudioWordDetection.Words.Add(new WordDetails() { Label = WORD_UP }); AudioWordDetection.Words.Add(new WordDetails() { Label = WORD_DOWN }); AudioWordDetection.WordsToIgnore.Add(WORD_PUSH_TO_TALK); //subscribe detection event AudioWordDetection.WordDetectedEvent += WordDetectedHandler; }
public DictViewModel() { Title = Language.txtTitleDictation; ButtonEnabled = true; lstSpecialWords = new List <SpecialWords>(); ShuffleCommand = new Command(new Action(ShuffleCommandAction)); SayCommand = new Command(new Action <object>(SayItCommandAction), CanSayItCommandAction); CheckCommand = new Command(new Action <object>(CheckCommandAction), new Func <object, bool>(CanCheckCommandAction)); wordDetails = new WordDetails(); wordDetails.TypingWordFinished += Wp_TypingWordFinished; wordDetails.TypingCancelled += Wp_TypingCancelled; SayCommand.ChangeCanExecute(); var assembly = IntrospectionExtensions.GetTypeInfo(typeof(DictViewModel)).Assembly; Stream stream = assembly.GetManifestResourceStream("MultiplicationTable.XMLText.xml"); txtXml = string.Empty; using (var reader = new System.IO.StreamReader(stream)) { txtXml = reader.ReadToEnd(); } xDoc = XDocument.Parse(txtXml); //CHECK IF USER ADDED USER DEFINED DICTATIONS Task t = new Task(async() => { try { IFolder folder = PCLStorage.FileSystem.Current.LocalStorage; if (await PCLHelper.IsFolderExistAsync("UserXML", folder)) { IFolder destFolder = await folder.GetFolderAsync("UserXML"); if (await PCLHelper.IsFileExistAsync("UserDict.xml", destFolder)) { IFile file = await destFolder.GetFileAsync("UserDict.xml"); string content = await file.ReadAllTextAsync(); if (!string.IsNullOrEmpty(content)) { xDocUser = XDocument.Parse(content); } } } } catch (Exception ex) { UserDialogs.Instance.Alert(Language.txtErrLoadingUserData + " " + ex.Message, Language.btnOk); } }); t.RunSynchronously(); }
void LoadWord(BinaryReader br, WordDetails details) { details.Label = br.ReadString(); int size = br.ReadInt32(); details.Wave = new float[size]; for (int index = 0; index < size; ++index) { details.Wave[index] = br.ReadSingle(); } }
private string GetNextWord(WordDetails wordDetails, string text) { var splitedWord = text.Substring(wordDetails.Length + 1); if (!string.IsNullOrEmpty(splitedWord)) { return(splitedWord.Substring(0, splitedWord.IndexOf(" ", StringComparison.Ordinal))); } //that means selected word is the last one return(string.Empty); }
// Hilangkan noise di semua word yang sudah direkam private void Refilter() { if (null == AudioWordDetection) { return; } for (int index = 1; index < AudioWordDetection.Words.Count; ++index) { WordDetails details = AudioWordDetection.Words[index]; Mic.RemoveSpectrumNoise(GetWord("Noise").SpectrumReal, details.SpectrumReal); } }
public void SaveProfilesPrefs(string key) { try { int count = 0; for (int wordIndex = 0; wordIndex < Words.Count; ++wordIndex) { WordDetails details = Words[wordIndex]; if (null == details) { continue; } ++count; } PlayerPrefs.SetInt(key, count); Debug.Log(string.Format("Saving profiles count={0}", count)); int index = 0; for (int wordIndex = 0; wordIndex < Words.Count; ++wordIndex) { WordDetails details = Words[wordIndex]; if (null == details) { continue; } string wordKey = string.Format("{0}_{1}", key, index); using (MemoryStream ms = new MemoryStream()) { using (BinaryWriter bw = new BinaryWriter(ms)) { SaveWord(bw, details); bw.Flush(); ms.Position = 0; byte[] buffer = ms.GetBuffer(); string base64 = System.Convert.ToBase64String(buffer); PlayerPrefs.SetString(wordKey, base64); Debug.Log(string.Format("Key={0} size={1} label={2}", wordKey, base64.Length, details.Label)); } } ++index; } } catch (Exception ex) { Debug.LogError(string.Format("Failed to save profiles exception={0}", ex)); } }
/// <summary> /// Refilter all the samples, removing noise /// </summary> protected void Refilter() { if (null == AudioWordDetection) { return; } for (int index = 1; index < AudioWordDetection.Words.Count; ++index) { WordDetails details = AudioWordDetection.Words[index]; _Mic.RemoveSpectrumNoise(GetWord(WORD_NOISE).SpectrumReal, details.SpectrumReal); } }
private void UpdateMic() { // set device mic if (string.IsNullOrEmpty(Mic.DeviceName)) { foreach (string device in Microphone.devices) { if (string.IsNullOrEmpty(device)) { continue; } Mic.DeviceName = device; } } if (null == AudioWordDetection || null == Mic || string.IsNullOrEmpty(Mic.DeviceName)) { return; } // load profile suara pemain if (!haveLoad) { LoadProfile(FILE_PROFILES); haveLoad = true; } if (GamePrefs.isVoiceUsed) { // Deteksi Jurus if (AudioWordDetection.ClosestIndex == 1 && ultiAvailable) { // pake skill ultiAvailable = false; ultiReady = false; if (Network.isServer) { server_doSkill(Network.player, 2); } else { networkView.RPC("server_doSkill", RPCMode.Server, Network.player, 2); } //DoUltimate(); WordDetails details = AudioWordDetection.Words[0]; // Debug.Log(details.Score.ToString()); } } }
//Open the selected file with the corresponding program private void Row_DoubleClick(object sender, MouseButtonEventArgs e) { if (e.ChangedButton == MouseButton.Left) { FileDetails fl = FileList.SelectedItem as FileDetails; ImageDetails Il = FileList.SelectedItem as ImageDetails; WordDetails Wl = FileList.SelectedItem as WordDetails; PDFdetails Pl = FileList.SelectedItem as PDFdetails; VideoDetails Vl = FileList.SelectedItem as VideoDetails; AudioDetails Al = FileList.SelectedItem as AudioDetails; OtherDetails Ol = FileList.SelectedItem as OtherDetails; try { if (fl != null) { System.Diagnostics.Process.Start(fl.path.ToString()); } if (Il != null) { System.Diagnostics.Process.Start(Il.Path.ToString()); } if (Wl != null) { System.Diagnostics.Process.Start(Wl.path.ToString()); } if (Pl != null) { System.Diagnostics.Process.Start(Wl.path.ToString()); } if (Vl != null) { System.Diagnostics.Process.Start(Vl.path.ToString()); } if (Al != null) { System.Diagnostics.Process.Start(Al.path.ToString()); } if (Ol != null) { System.Diagnostics.Process.Start(Ol.path.ToString()); } } catch (Exception ex) { System.Windows.MessageBox.Show("Imposible d'ouvir le fichier" + ex.Message); } } }
public void LoadProfiles(BinaryReader br) { Words.Clear(); int wordCount = br.ReadInt32(); for (int wordIndex = 0; wordIndex < wordCount; ++wordIndex) { WordDetails details = new WordDetails(); Words.Add(details); LoadWord(br, details); } }
private void SaveWord(BinaryWriter bw, WordDetails details) { bw.Write(details.Label); if (null == details.Wave) { bw.Write(0); } else { bw.Write(details.Wave.Length); foreach (float f in details.Wave) { bw.Write(f); } } }
private static string GetPreviousWord(WordDetails wordDetails, string text) { //if is first word we don't have prev word if (wordDetails.Position.Equals(0)) { return(string.Empty); } var firstPartOfString = text.Substring(0, wordDetails.Position).TrimEnd(); var lastIndexOfSpace = firstPartOfString.LastIndexOf(" ", StringComparison.Ordinal); if (lastIndexOfSpace != -1) { return(firstPartOfString.Substring(lastIndexOfSpace)); } //if user deselected only a part from the word return(string.Empty); }
protected virtual void SetupWordProfile(WordDetails details, bool isNoise) { //||string.IsNullOrEmpty(Mic.DeviceName) if (null == AudioWordDetection || null == _Mic) { return; } int size = details.Wave.Length; int halfSize = size / 2; //allocate profile spectrum, real if (null == details.SpectrumReal || details.SpectrumReal.Length != halfSize) { details.SpectrumReal = new float[halfSize]; } //allocate profile spectrum, imaginary if (null == details.SpectrumImag || details.SpectrumImag.Length != halfSize) { details.SpectrumImag = new float[halfSize]; } //get the spectrum for the trimmed word if (null != details.Wave && details.Wave.Length > 0) { _Mic.GetSpectrumData(details.Wave, details.SpectrumReal, details.SpectrumImag, FFTWindow.Rectangular); } //filter noise if (RemoveSpectrumNoise) { if (isNoise) { Refilter(); } else { _Mic.RemoveSpectrumNoise(GetWord(WORD_NOISE).SpectrumReal, details.SpectrumReal); } } }
public void SaveWord(BinaryWriter bw, WordDetails details) { bw.Write(details.Label); bw.Write(details.Audio.channels); bw.Write(details.Audio.frequency); if (null == details.Wave) { bw.Write(0); } else { bw.Write(details.Wave.Length); foreach (float f in details.Wave) { bw.Write(f); } } }
private void MenuItem_OnClick(object sender, RoutedEventArgs e) { try { var docStart = _textBox.Document.ContentStart; var start = _textBox.Selection.Start; var end = _textBox.Selection.End; var parent = (RichTextBox)_textBox.Document.Parent; var tag = string.Empty; if (parent != null) { tag = (string)parent.Tag; } var tr = new TextRange(start, end); tr.ApplyPropertyValue(TextElement.BackgroundProperty, Brushes.LightSalmon); var dataContext = _textBox.DataContext as ContentSearchResult; var startRange = new TextRange(docStart, start); var indexStartAbs = startRange.Text.Length; var text = new TextRange(docStart, _textBox.Document.ContentEnd).Text.TrimEnd(); var wordDetails = new WordDetails { Position = indexStartAbs, Length = indexStartAbs + _textBox.Selection.Text.TrimEnd().Length, Text = _textBox.Selection.Text.TrimEnd() }; var nextWord = GetNextWord(wordDetails, text); wordDetails.NextWord = nextWord; if (tag.Equals("SourceBox")) { dataContext?.SelectedWordsDetails.Add(wordDetails); } else { dataContext?.TargetSelectedWordsDetails.Add(wordDetails); } } catch (Exception) { // ignored } }
//Open the directory of the selected file private void Row_RightClick(object sender, RoutedEventArgs e) { FileDetails fl = FileList.SelectedItem as FileDetails; ImageDetails Il = FileList.SelectedItem as ImageDetails; WordDetails Wl = FileList.SelectedItem as WordDetails; PDFdetails Pl = FileList.SelectedItem as PDFdetails; VideoDetails Vl = FileList.SelectedItem as VideoDetails; AudioDetails Al = FileList.SelectedItem as AudioDetails; OtherDetails Ol = FileList.SelectedItem as OtherDetails; if (fl != null) { var test = fl.folderPath; Process.Start("explorer.exe", fl.folderPath.ToString()); } if (Il != null) { Process.Start("explorer.exe", Il.folderPath.ToString()); } if (Wl != null) { Process.Start("explorer.exe", Wl.folderPath.ToString()); } if (Pl != null) { Process.Start("explorer.exe", Pl.folderPath.ToString()); } if (Vl != null) { Process.Start("explorer.exe", Vl.folderPath.ToString()); } if (Al != null) { Process.Start("explorer.exe", Al.folderPath.ToString()); } if (Ol != null) { Process.Start("explorer.exe", Ol.folderPath.ToString()); } }
protected void DisplayProfileLoadSave(string key) { GUILayout.BeginHorizontal(); GUILayout.Label(string.Empty, GUILayout.Width(150)); GUILayout.Label("Profiles:"); GUILayout.Label(string.Empty, GUILayout.Width(30)); if (GUILayout.Button("Load", GUILayout.MinHeight(40))) { if ( //AudioWordDetection.LoadProfiles(new FileInfo(key)) //|| AudioWordDetection.LoadProfilesPrefs(key)) //) { for (int wordIndex = 0; wordIndex < AudioWordDetection.Words.Count; ++wordIndex) { WordDetails details = AudioWordDetection.Words[wordIndex]; if (null != details.Wave && details.Wave.Length > 0) { if (null == details.Audio) { details.Audio = AudioClip.Create(string.Empty, details.Wave.Length, 1, _Mic.SampleRate, false, false); } details.Audio.SetData(details.Wave, 0); GetComponent <AudioSource>().loop = false; GetComponent <AudioSource>().mute = false; } SetupWordProfile(details, false); } } } GUILayout.Label(string.Empty, GUILayout.Width(30)); if (GUILayout.Button("Save", GUILayout.MinHeight(40))) { //AudioWordDetection.SaveProfiles(new FileInfo(key)); AudioWordDetection.SaveProfilesPrefs(key); } GUILayout.EndHorizontal(); }
public bool LoadProfilesPrefs(string key) { try { if (!PlayerPrefs.HasKey(key)) { Debug.LogError("Player prefs missing key"); return(false); } Words.Clear(); int wordCount = PlayerPrefs.GetInt(key); for (int wordIndex = 0; wordIndex < wordCount; ++wordIndex) { string wordKey = string.Format("{0}_{1}", key, wordIndex); if (PlayerPrefs.HasKey(wordKey)) { string base64 = PlayerPrefs.GetString(wordKey); byte[] buffer = System.Convert.FromBase64String(base64); using (MemoryStream ms = new MemoryStream(buffer)) { using (BinaryReader br = new BinaryReader(ms)) { WordDetails details = new WordDetails(); Words.Add(details); LoadWord(br, details); Debug.Log(string.Format("Key={0} size={1} label={2}", wordKey, base64.Length, details.Label)); } } } } return(true); } catch (Exception ex) { Debug.LogError(string.Format("Failed to load profiles exception={0}", ex)); return(false); } }
private void UnselectWord(object sender, RoutedEventArgs e) { var docStart = _textBox.Document.ContentStart; var start = _textBox.Selection.Start; var end = _textBox.Selection.End; var parent = (RichTextBox)_textBox.Document.Parent; var tag = string.Empty; if (parent != null) { tag = (string)parent.Tag; } var tr = new TextRange(start, end); tr.ApplyPropertyValue(TextElement.BackgroundProperty, Brushes.White); var dataContext = _textBox.DataContext as ContentSearchResult; var startRange = new TextRange(docStart, start); var indexStartAbs = startRange.Text.Length; var text = new TextRange(docStart, _textBox.Document.ContentEnd).Text.TrimEnd(); var wordDetails = new WordDetails { Position = indexStartAbs, Length = indexStartAbs + _textBox.Selection.Text.TrimEnd().Length, Text = _textBox.Selection.Text.TrimEnd() }; var prevWord = GetPreviousWord(wordDetails, text); wordDetails.PreviousWord = prevWord; if (tag.Equals("SourceBox")) { dataContext?.DeSelectedWordsDetails.Add(wordDetails); } else { dataContext?.TargetDeSelectedWordsDetails.Add(wordDetails); } }
public void DetectWords(float[] wave) { float minScore = 0f; int closestIndex = 0; WordDetails closestWord = null; int size = wave.Length; int halfSize = size / 2; for (int wordIndex = FIRST_WORD_INDEX; wordIndex < Words.Count; ++wordIndex) { WordDetails details = Words[wordIndex]; if (null == details) { continue; } if (WordsToIgnore.Contains(details.Label)) { continue; } float[] spectrum = details.SpectrumReal; if (null == spectrum) { //Debug.LogError(string.Format("Word profile not set: {0}", details.Label)); details.Score = -1; continue; } if (null == m_spectrumReal) { details.Score = -1; continue; } if (spectrum.Length != halfSize || m_spectrumReal.Length != halfSize) { details.Score = -1; continue; } float score = 0; for (int index = 0; index < halfSize;) { float sumSpectrum = 0f; float sumProfile = 0f; int nextIndex = index + Threshold; for (; index < nextIndex && index < halfSize; ++index) { sumSpectrum += Mathf.Abs(m_spectrumReal[index]); sumProfile += Mathf.Abs(spectrum[index]); } sumProfile = sumProfile / (float)Threshold; sumSpectrum = sumSpectrum / (float)Threshold; float val = Mathf.Abs(sumSpectrum - sumProfile); score += Mathf.Abs(val); } details.Score = score; #if USE_WORD_MIN_SCORE details.AddMinScore(score); score = details.GetMinScore(DateTime.Now - TimeSpan.FromSeconds(1)); #endif if (wordIndex == FIRST_WORD_INDEX) { closestIndex = wordIndex; minScore = score; closestWord = details; } else if (score < minScore) { closestIndex = wordIndex; minScore = score; closestWord = details; } } if (ClosestIndex != closestIndex) { ClosestIndex = closestIndex; if (null != WordDetectedEvent) { WordEventArgs args = new WordEventArgs(); args.Details = closestWord; //Debug.Log(args.Details.Label); WordDetectedEvent.Invoke(this, args); } } }
/// <summary> /// Initialize the example /// </summary> protected override void Start() { if (null == AudioWordDetection || null == Mic) { Debug.LogError("Missing meta references"); return; } m_Noise = Duplicate(m_PrefabIdle); for (int index = 0; index < m_expressions.Length; ++index) { m_expressions[index] = Duplicate(m_expressions[index]); } Dictionary<String, WordDetails> words = new Dictionary<String, WordDetails>(); WordDetails noise = new WordDetails() {Label = "Noise"}; AudioWordDetection.Words.Add(noise); // prepopulate words foreach (MeshRenderer expression in m_expressions) { //Debug.Log(val); String command = expression.name; WordDetails details = new WordDetails() { Label = command }; AudioWordDetection.Words.Add(details); words[command] = details; #if !UNITY_WEBPLAYER try { string path = string.Format("Assets/{0}_{1}.profile", GetType().Name, command); if (File.Exists(path)) { using ( FileStream fs = File.Open(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite) ) { using (BinaryReader br = new BinaryReader(fs)) { AudioWordDetection.LoadWord(br, details); //Debug.Log(string.Format("Loaded profile: {0}", path)); details.Label = command; } } } else { Debug.Log(string.Format("Profile not available for: {0}", path)); } } catch (Exception ex) { Debug.LogError(string.Format("Failed to load word: {0}", ex)); } #endif } //subscribe detection event AudioWordDetection.WordDetectedEvent += WordDetectedHandler; }
public void LoadProfiles(BinaryReader br) { Words.Clear(); int wordCount = br.ReadInt32(); for (int wordIndex = 0; wordIndex < wordCount; ++wordIndex) { WordDetails details = new WordDetails(); Words.Add(details); LoadWord(br, details); } }
public bool LoadProfilesPrefs(string key) { try { if (!PlayerPrefs.HasKey(key)) { Debug.LogError("Player prefs missing key"); return false; } Words.Clear(); int wordCount = PlayerPrefs.GetInt(key); for (int wordIndex = 0; wordIndex < wordCount; ++wordIndex) { string wordKey = string.Format("{0}_{1}", key, wordIndex); if (PlayerPrefs.HasKey(wordKey)) { string base64 = PlayerPrefs.GetString(wordKey); byte[] buffer = System.Convert.FromBase64String(base64); using (MemoryStream ms = new MemoryStream(buffer)) { using (BinaryReader br = new BinaryReader(ms)) { WordDetails details = new WordDetails(); Words.Add(details); LoadWord(br, details); Debug.Log(string.Format("Key={0} size={1} label={2}", wordKey, base64.Length, details.Label)); } } } } return true; } catch (Exception ex) { Debug.LogError(string.Format("Failed to load profiles exception={0}", ex)); return false; } }
/// <summary> /// Initialize the example /// </summary> protected override void Start() { if (null == AudioWordDetection || null == Mic) { Debug.LogError("Missing meta references"); return; } WordDetails wordNoise = new WordDetails() { Label = WORD_NOISE }; // prepopulate words AudioWordDetection.Words.Add(wordNoise); AudioWordDetection.Words.Add(new WordDetails() { Label = WORD_PUSH_TO_TALK }); AudioWordDetection.Words.Add(new WordDetails() { Label = WORD_RESET }); AudioWordDetection.Words.Add(new WordDetails() { Label = WORD_GROW }); AudioWordDetection.Words.Add(new WordDetails() { Label = WORD_SHRINK }); AudioWordDetection.Words.Add(new WordDetails() { Label = WORD_LEFT }); AudioWordDetection.Words.Add(new WordDetails() { Label = WORD_RIGHT }); AudioWordDetection.Words.Add(new WordDetails() { Label = WORD_UP }); AudioWordDetection.Words.Add(new WordDetails() { Label = WORD_DOWN }); AudioWordDetection.WordsToIgnore.Add(WORD_PUSH_TO_TALK); //subscribe detection event AudioWordDetection.WordDetectedEvent += WordDetectedHandler; }
protected virtual void SetupWordProfile(WordDetails details, bool isNoise) { if (null == AudioWordDetection || null == Mic || string.IsNullOrEmpty(Mic.DeviceName)) { return; } int size = details.Wave.Length; int halfSize = size/2; //allocate profile spectrum, real if (null == details.SpectrumReal || details.SpectrumReal.Length != halfSize) { details.SpectrumReal = new float[halfSize]; } //allocate profile spectrum, imaginary if (null == details.SpectrumImag || details.SpectrumImag.Length != halfSize) { details.SpectrumImag = new float[halfSize]; } //get the spectrum for the trimmed word if (null != details.Wave && details.Wave.Length > 0) { Mic.GetSpectrumData(details.Wave, details.SpectrumReal, details.SpectrumImag, FFTWindow.Rectangular); } //filter noise if (RemoveSpectrumNoise) { if (isNoise) { Refilter(); } else { Mic.RemoveSpectrumNoise(GetWord(WORD_NOISE).SpectrumReal, details.SpectrumReal); } } }
/// <summary> /// GUI event /// </summary> protected virtual void OnGUI() { if (null == AudioWordDetection || null == Mic || string.IsNullOrEmpty(Mic.DeviceName)) { return; } DisplayProfileLoadSave(FILE_PROFILES); if (GUILayout.Button("Add Word", GUILayout.Height(45))) { WordDetails details = new WordDetails(); details.Label = AudioWordDetection.Words.Count.ToString(); AudioWordDetection.Words.Add(details); } GUILayout.Space(10); Color backgroundColor = GUI.backgroundColor; for (int wordIndex = 0; wordIndex < AudioWordDetection.Words.Count; ++wordIndex) { if (AudioWordDetection.ClosestIndex == wordIndex) { GUI.backgroundColor = Color.red; } else { GUI.backgroundColor = backgroundColor; } if (wordIndex > 0) { GUI.enabled = null != GetWord(WORD_NOISE).SpectrumReal; } GUILayout.BeginHorizontal(); WordDetails details = AudioWordDetection.Words[wordIndex]; if (wordIndex == 0) { GUILayout.Label(details.Label, GUILayout.Width(150), GUILayout.Height(45)); } else { details.Label = GUILayout.TextField(details.Label, GUILayout.Width(150), GUILayout.Height(45)); } GUILayout.Button(string.Format("{0}", (null == details.SpectrumReal) ? "not set" : "set"), GUILayout.Height(45)); Event e = Event.current; if (null != e) { Rect rect = GUILayoutUtility.GetLastRect(); bool overButton = rect.Contains(e.mousePosition); if (m_buttonIndex == -1 && m_timerStart == DateTime.MinValue && Input.GetMouseButton(0) && overButton) { //Debug.Log("Initial button down"); m_buttonIndex = wordIndex; m_startPosition = Mic.GetPosition(); m_timerStart = DateTime.Now + TimeSpan.FromSeconds(Mic.CaptureTime); } if (m_buttonIndex == wordIndex) { bool buttonUp = Input.GetMouseButtonUp(0); if (m_timerStart > DateTime.Now && !buttonUp) { //Debug.Log("Button still pressed"); } else if (m_timerStart != DateTime.MinValue && m_timerStart < DateTime.Now) { //Debug.Log("Button timed out"); SetupWordProfile(false); m_timerStart = DateTime.MinValue; m_buttonIndex = -1; } else if (m_timerStart != DateTime.MinValue && buttonUp && m_buttonIndex != -1) { //Debug.Log("Button is no longer pressed"); SetupWordProfile(true); m_timerStart = DateTime.MinValue; m_buttonIndex = -1; } } } GUI.enabled = null != details.Audio; if (GUILayout.Button("Play", GUILayout.Height(45))) { if (null != details.Audio) { if (NormalizeWave) { GetComponent<AudioSource>().PlayOneShot(details.Audio, 0.1f); } else { GetComponent<AudioSource>().PlayOneShot(details.Audio); } } // show profile RefExample.OverrideSpectrumImag = true; RefExample.SpectrumImag = details.SpectrumReal; } GUI.enabled = wordIndex > 0; if (wordIndex > 0 && GUILayout.Button("Remove", GUILayout.Height(45))) { AudioWordDetection.Words.RemoveAt(wordIndex); --wordIndex; } GUILayout.Label(details.Score.ToString()); GUILayout.EndHorizontal(); if (wordIndex > 0) { GUI.enabled = null != GetWord(WORD_NOISE).SpectrumReal; } GUILayout.Space(10); } GUI.backgroundColor = backgroundColor; }
private void SaveWord(BinaryWriter bw, WordDetails details) { bw.Write(details.Label); if (null == details.Wave) { bw.Write(0); } else { bw.Write(details.Wave.Length); foreach (float f in details.Wave) { bw.Write(f); } } }
/// <summary> /// Initialize the example /// </summary> protected override void Start() { if (null == AudioWordDetection || null == Mic) { Debug.LogError("Missing meta references"); return; } Dictionary <Commands, WordDetails> words = new Dictionary <Commands, WordDetails>(); // prepopulate words foreach (string val in Enum.GetNames(typeof(Commands))) { //Debug.Log(val); Commands command = (Commands)Enum.Parse(typeof(Commands), val); WordDetails details = new WordDetails() { Label = val }; words[command] = details; try { string path = string.Format("Assets/{0}_{1}.profile", GetType().Name, val); if (File.Exists(path)) { using ( FileStream fs = File.Open(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite) ) { using (BinaryReader br = new BinaryReader(fs)) { AudioWordDetection.LoadWord(br, details); //Debug.Log(string.Format("Loaded profile: {0}", path)); details.Label = val; } } } else { Debug.Log(string.Format("Profile not available for: {0}", path)); } } catch (Exception ex) { Debug.LogError(string.Format("Failed to load word: {0}", ex)); } } // set 1 m_set1.Add(words[Commands.Noise]); m_set1.Add(words[Commands.Go]); // set 2 m_set2.Add(words[Commands.Noise]); m_set2.Add(words[Commands.Back]); m_set2.Add(words[Commands.Action]); m_set2.Add(words[Commands.Misc]); // set 3 m_set3.Add(words[Commands.Noise]); m_set3.Add(words[Commands.Back]); m_set3.Add(words[Commands.Charge]); m_set3.Add(words[Commands.Elbow]); m_set3.Add(words[Commands.Head]); m_set3.Add(words[Commands.Punch]); // set 4 m_set4.Add(words[Commands.Noise]); m_set4.Add(words[Commands.Back]); m_set4.Add(words[Commands.Dance]); m_set4.Add(words[Commands.Fall]); m_set4.Add(words[Commands.Guitar]); m_set4.Add(words[Commands.Run]); AudioWordDetection.Words = m_set1; m_mode = Modes.Set1; //subscribe detection event AudioWordDetection.WordDetectedEvent += WordDetectedHandler; }
/// <summary> /// Initialize the example /// </summary> protected override void Start() { if (null == AudioWordDetection || null == Mic) { Debug.LogError("Missing meta references"); return; } Dictionary<String, WordDetails> words = new Dictionary<String, WordDetails>(); WordDetails noise = new WordDetails() { Label = "Noise" }; AudioWordDetection.Words.Add(noise); string[] navigation = { WordDetectionInput.KEY_JUMP, WordDetectionInput.KEY_FORWARD, WordDetectionInput.KEY_BACKWARD, WordDetectionInput.KEY_LEFT, WordDetectionInput.KEY_RIGHT, }; // prepopulate words foreach (string command in navigation) { //Debug.Log(command); if (command == "idle") { continue; } WordDetails details = new WordDetails() { Label = command }; AudioWordDetection.Words.Add(details); words[command] = details; #if !UNITY_WEBPLAYER try { string path = string.Format("Assets/{0}_{1}.profile", GetType().Name, command); if (File.Exists(path)) { using ( FileStream fs = File.Open(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite) ) { using (BinaryReader br = new BinaryReader(fs)) { AudioWordDetection.LoadWord(br, details); //Debug.Log(string.Format("Loaded profile: {0}", path)); details.Label = command; } } } else { Debug.Log(string.Format("Profile not available for: {0}", path)); } } catch (Exception ex) { Debug.LogError(string.Format("Failed to load word: {0}", ex)); } #endif } //subscribe detection event AudioWordDetection.WordDetectedEvent += WordDetectedHandler; }
/// <summary> /// GUI event /// </summary> protected override void OnGUI() { ExampleUpdate(); if (null == AudioWordDetection || null == Mic || string.IsNullOrEmpty(Mic.DeviceName)) { return; } DisplayProfileLoadSave(FILE_PROFILES); Color backgroundColor = GUI.backgroundColor; for (int wordIndex = 0; wordIndex < AudioWordDetection.Words.Count; ++wordIndex) { if (AudioWordDetection.ClosestIndex == wordIndex) { GUI.backgroundColor = Color.red; } else { GUI.backgroundColor = backgroundColor; } WordDetails noise = GetWord(WORD_NOISE); if (null == noise) { continue; } if (wordIndex > 0) { GUI.enabled = null != noise.SpectrumReal; } GUILayout.BeginHorizontal(); WordDetails details = AudioWordDetection.Words[wordIndex]; if (GUILayout.Button("Play", GUILayout.Height(45))) { if (null != details.Audio) { if (NormalizeWave) { audio.PlayOneShot(details.Audio, 0.1f); } else { audio.PlayOneShot(details.Audio); } } // show profile RefExample.OverrideSpectrumImag = true; RefExample.SpectrumImag = details.SpectrumReal; } if (wordIndex == 0) { GUILayout.Label(details.Label, GUILayout.Width(150), GUILayout.Height(45)); } else { details.Label = GUILayout.TextField(details.Label, GUILayout.Width(150), GUILayout.Height(45)); } GUILayout.Button(string.Format("{0}", (null == details.SpectrumReal) ? "not set" : "set"), GUILayout.Height(45)); Event e = Event.current; if (null != e) { Rect rect = GUILayoutUtility.GetLastRect(); bool overButton = rect.Contains(e.mousePosition); if (m_buttonIndex == -1 && m_timerStart == DateTime.MinValue && Input.GetMouseButton(0) && overButton) { //Debug.Log("Initial button down"); m_buttonIndex = wordIndex; m_startPosition = Mic.GetPosition(); m_timerStart = DateTime.Now + TimeSpan.FromSeconds(Mic.CaptureTime); } if (m_buttonIndex == wordIndex) { bool buttonUp = Input.GetMouseButtonUp(0); if (m_timerStart > DateTime.Now && !buttonUp) { //Debug.Log("Button still pressed"); } else if (m_timerStart != DateTime.MinValue && m_timerStart < DateTime.Now) { //Debug.Log("Button timed out"); SetupWordProfile(false); m_timerStart = DateTime.MinValue; m_buttonIndex = -1; } else if (m_timerStart != DateTime.MinValue && buttonUp && m_buttonIndex != -1) { //Debug.Log("Button is no longer pressed"); SetupWordProfile(true); m_timerStart = DateTime.MinValue; m_buttonIndex = -1; } } } GUILayout.Label(details.Score.ToString()); //GUILayout.Label(string.Format("{0}", details.GetMinScore(DateTime.Now - TimeSpan.FromSeconds(1)))); GUILayout.EndHorizontal(); if (wordIndex > 0) { GUI.enabled = null != noise.SpectrumReal; } GUILayout.Space(10); } GUI.backgroundColor = backgroundColor; }
/// <summary> /// Initialize the example /// </summary> protected override void Start() { if (null == AudioWordDetection || null == Mic) { Debug.LogError("Missing meta references"); return; } if (null == VideoStage) { Debug.LogError("Missing Video Stage"); return; } m_map.Add(Commands.Noise, new Mapping() { m_material = MaterialIdle, m_audioClip = null }); m_map.Add(Commands.One, new Mapping() { m_material = MaterialVideo1, m_audioClip = Audio1 }); m_map.Add(Commands.Two, new Mapping() { m_material = MaterialVideo2, m_audioClip = Audio2 }); m_map.Add(Commands.Three, new Mapping() { m_material = MaterialVideo3, m_audioClip = Audio3 }); m_map.Add(Commands.Four, new Mapping() { m_material = MaterialVideo4, m_audioClip = Audio4 }); m_map.Add(Commands.Five, new Mapping() { m_material = MaterialVideo5, m_audioClip = Audio5 }); // prepopulate words foreach (string val in Enum.GetNames(typeof(Commands))) { //Debug.Log(val); WordDetails details = new WordDetails() {Label = val}; AudioWordDetection.Words.Add(details); #if !UNITY_WEBPLAYER try { string path = string.Format("Assets/{0}_{1}.profile", GetType().Name, val); if (File.Exists(path)) { using ( FileStream fs = File.Open(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite) ) { using (BinaryReader br = new BinaryReader(fs)) { AudioWordDetection.LoadWord(br, details); //Debug.Log(string.Format("Loaded profile: {0}", path)); details.Label = val; } } } else { Debug.Log(string.Format("Profile not available for: {0}", path)); } } catch (Exception ex) { Debug.LogError(string.Format("Failed to load word: {0}", ex)); } #endif } //subscribe detection event AudioWordDetection.WordDetectedEvent += WordDetectedHandler; }
/// <summary> /// Initialize the example /// </summary> protected override void Start() { if (null == AudioWordDetection || null == Mic) { Debug.LogError("Missing meta references"); return; } Dictionary<Commands, WordDetails> words = new Dictionary<Commands, WordDetails>(); // prepopulate words foreach (string val in Enum.GetNames(typeof(Commands))) { //Debug.Log(val); Commands command = (Commands) Enum.Parse(typeof (Commands), val); WordDetails details = new WordDetails() { Label = val }; words[command] = details; try { string path = string.Format("Assets/{0}_{1}.profile", GetType().Name, val); if (File.Exists(path)) { using ( FileStream fs = File.Open(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite) ) { using (BinaryReader br = new BinaryReader(fs)) { AudioWordDetection.LoadWord(br, details); //Debug.Log(string.Format("Loaded profile: {0}", path)); details.Label = val; } } } else { Debug.Log(string.Format("Profile not available for: {0}", path)); } } catch (Exception ex) { Debug.LogError(string.Format("Failed to load word: {0}", ex)); } } // set 1 m_set1.Add(words[Commands.Noise]); m_set1.Add(words[Commands.Go]); // set 2 m_set2.Add(words[Commands.Noise]); m_set2.Add(words[Commands.Back]); m_set2.Add(words[Commands.Action]); m_set2.Add(words[Commands.Misc]); // set 3 m_set3.Add(words[Commands.Noise]); m_set3.Add(words[Commands.Back]); m_set3.Add(words[Commands.Charge]); m_set3.Add(words[Commands.Elbow]); m_set3.Add(words[Commands.Head]); m_set3.Add(words[Commands.Punch]); // set 4 m_set4.Add(words[Commands.Noise]); m_set4.Add(words[Commands.Back]); m_set4.Add(words[Commands.Dance]); m_set4.Add(words[Commands.Fall]); m_set4.Add(words[Commands.Guitar]); m_set4.Add(words[Commands.Run]); AudioWordDetection.Words = m_set1; m_mode = Modes.Set1; //subscribe detection event AudioWordDetection.WordDetectedEvent += WordDetectedHandler; }
//Creates the datalist model public void makeList() { listFile = RetrieveList.myList.ToList(); if (RetrieveList.RadiobuttonKeep.Contains("Word")) { if (RetrieveList.mywordList != null) { RetrieveList.mywordList.Clear(); } wordFile.Clear(); foreach (var list in listFile) { if (list.filename.ToString().ToLower().Contains(".doc")) { WordDetails id = new WordDetails() { content = GetWord(list.path.ToString()), name = list.filename, path = list.path, folderPath = list.folderPath }; wordFile.Add(id); } } IEnumerable <WordDetails> sansDoublonWord = wordFile.Distinct(); int num = wordFile.Count(); CountElement(num); RetrieveList.mywordList = wordFile.ToObservableCollection(); } if (RetrieveList.RadiobuttonKeep.Contains("PDF")) { if (RetrieveList.mypdfList != null) { RetrieveList.mypdfList.Clear(); } PDFFile.Clear(); foreach (var list in listFile) { if (list.filename.ToString().ToLower().Contains(".pdf")) { PDFdetails id = new PDFdetails() { content = GetPDF(list.path.ToString()), name = list.filename, path = list.path, folderPath = list.folderPath }; PDFFile.Add(id); } } IEnumerable <PDFdetails> sansDoublonPDF = PDFFile.Distinct(); int num = sansDoublonPDF.Count(); CountElement(num); RetrieveList.mypdfList = PDFFile.ToObservableCollection(); } if (RetrieveList.RadiobuttonKeep.Contains("Images")) { if (RetrieveList.myimageList != null) { RetrieveList.myimageList.Clear(); } imageFile.Clear(); foreach (var list in listFile) { if (Extentions_Image.Any(list.filename.ToLower().Contains)) { ImageDetails id = new ImageDetails() { FileName = list.filename, Path = list.path, folderPath = list.folderPath }; imageFile.Add(id); } } IEnumerable <ImageDetails> sansDoublonImage = imageFile.Distinct(); int num = sansDoublonImage.Count(); CountElement(num); RetrieveList.myimageList = imageFile.ToObservableCollection(); } if (RetrieveList.RadiobuttonKeep.Contains("Audio")) { if (RetrieveList.myaudioList != null) { RetrieveList.myaudioList.Clear(); } audioFile.Clear(); foreach (var list in listFile) { if (Extentions_Audio.Any(list.filename.ToLower().Contains)) { AudioDetails id = new AudioDetails() { FileName = list.filename, path = list.path, folderPath = list.folderPath }; audioFile.Add(id); } } IEnumerable <AudioDetails> sansDoublonAudio = audioFile.Distinct(); int num = sansDoublonAudio.Count(); CountElement(num); RetrieveList.myaudioList = audioFile.ToObservableCollection(); } if (RetrieveList.RadiobuttonKeep.Contains("Vidéos")) { if (RetrieveList.myvideoList != null) { RetrieveList.myvideoList.Clear(); } videoFile.Clear(); foreach (var list in listFile) { if (Extentions_Video.Any(list.filename.ToString().ToLower().Contains)) { VideoDetails id = new VideoDetails { FileName = list.filename, path = list.path, folderPath = list.folderPath }; videoFile.Add(id); } } IEnumerable <VideoDetails> sansDoublonVideo = videoFile.Distinct(); int num = sansDoublonVideo.Count(); CountElement(num); RetrieveList.myvideoList = videoFile.ToObservableCollection(); } if (RetrieveList.RadiobuttonKeep.Contains("Autres")) { if (RetrieveList.myotherList != null) { RetrieveList.myotherList.Clear(); } otherFile.Clear(); foreach (var list in listFile) { if (!Extentions_All.Any(list.filename.ToString().ToLower().Contains)) { OtherDetails id = new OtherDetails { FileName = list.filename, path = list.path, folderPath = list.folderPath }; otherFile.Add(id); } } IEnumerable <OtherDetails> sansDoublonOther = otherFile.Distinct(); int num = sansDoublonOther.Count(); CountElement(num); RetrieveList.myotherList = otherFile.ToObservableCollection(); } }
void LoadWord(BinaryReader br, WordDetails details) { details.Label = br.ReadString(); int size = br.ReadInt32(); details.Wave = new float[size]; for (int index = 0; index < size; ++index) { details.Wave[index] = br.ReadSingle(); } }
/// <summary> /// Initialize the example /// </summary> protected override void Start() { if (null == AudioWordDetection || null == Mic) { Debug.LogError("Missing meta references"); return; } if (null == Head) { Debug.LogError("Missing Head"); return; } if (null == Head.sharedMesh) { Debug.LogError("Missing Head Shared Mesh"); return; } Mesh mesh = Head.sharedMesh; for (int index = 0; index < Head.sharedMesh.blendShapeCount; ++index) { m_blendShapes.Add(mesh.GetBlendShapeName(index)); } Dictionary<String, WordDetails> words = new Dictionary<String, WordDetails>(); WordDetails noise = new WordDetails() { Label = "Noise" }; AudioWordDetection.Words.Add(noise); // prepopulate words foreach (string command in m_blendShapes) { //Debug.Log(command); if (command == "idle") { continue; } WordDetails details = new WordDetails() { Label = command }; AudioWordDetection.Words.Add(details); words[command] = details; #if !UNITY_WEBPLAYER try { string path = string.Format("Assets/{0}_{1}.profile", GetType().Name, command); if (File.Exists(path)) { using ( FileStream fs = File.Open(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite) ) { using (BinaryReader br = new BinaryReader(fs)) { AudioWordDetection.LoadWord(br, details); //Debug.Log(string.Format("Loaded profile: {0}", path)); details.Label = command; } } } else { Debug.Log(string.Format("Profile not available for: {0}", path)); } } catch (Exception ex) { Debug.LogError(string.Format("Failed to load word: {0}", ex)); } #endif } //subscribe detection event AudioWordDetection.WordDetectedEvent += WordDetectedHandler; }
public void SaveWord(BinaryWriter bw, WordDetails details) { bw.Write(details.Label); bw.Write(details.Audio.channels); bw.Write(details.Audio.frequency); if (null == details.Wave) { bw.Write(0); } else { bw.Write(details.Wave.Length); foreach (float f in details.Wave) { bw.Write(f); } } }
void SaveProfile(WordDetails details) { #if !UNITY_WEBPLAYER string path = string.Format("Assets/{0}_{1}.profile", GetType().Name, details.Label); if (!string.IsNullOrEmpty(path)) { try { using ( FileStream fs = File.Open(path, FileMode.OpenOrCreate, FileAccess.Write, FileShare.ReadWrite) ) { using (BinaryWriter bw = new BinaryWriter(fs)) { AudioWordDetection.SaveWord(bw, details); //Debug.Log(string.Format("Save profile: {0}", details.Label)); } } } catch (Exception) { Debug.LogError(string.Format("Failed to save profile: {0}", details.Label)); } } #endif }
public void LoadWord(BinaryReader br, WordDetails details) { details.Label = br.ReadString(); int channels = br.ReadInt32(); int frequency = br.ReadInt32(); int size = br.ReadInt32(); details.Wave = new float[size]; for (int index = 0; index < size; ++index) { details.Wave[index] = br.ReadSingle(); } int halfSize = size / 2; details.SpectrumImag = new float[halfSize]; details.SpectrumReal = new float[halfSize]; Mic.GetSpectrumData(details.Wave, details.SpectrumReal, details.SpectrumImag, FFTWindow.Rectangular); if (null == details.Audio) { details.Audio = AudioClip.Create(Guid.NewGuid().ToString(), size, channels, frequency, false, false); } if (null != details.Audio && null != details.Wave) { details.Audio.SetData(details.Wave, 0); } }