1/06/2017

重構的路上

begin..
更新完 2 篇 2016的紀錄後(居然只有兩篇),2017一開始的挑戰就是對大型專案做架構分析整理 (ドキドキ)
之前陸陸續續有在接觸的 refactor 應該頗有幫助的吧,我想這應該可以成為銜接的第一步 XD
開始整理一些 Pearson 出版的 Refactoring: Improving The Design of Existing Code,重構雖然也可以靠經驗累積,但工具書的存在除了檢查以外,也有反思的幫助。 因為前面的概念比較不需要特別整理,筆記只想從第六章作起,最後完成到哪裡還是未知數,反正有必要的話也會對筆記重構一下(懶人發言)

Toward a Catalog of Refactoring

Format reference :
- name
- summary: what’s the problem, what to do, quick picture(code/UML)
- motivation:如果提煉動作可以強化程式碼清晰度,那就去做。
- mechanics
- example

Extract Method

about extract…
是最常見最基本的手法 : 提煉整理
[按] 大量簡化過長的函式

Inline Method

about Inline…
只被用過一次就 inline it (Replcae Temp with Query )
可以利用 final 做檢查
[按] 避免寫出更長的函式
[按] 利於檢視更多重構的可行性

int getLevel() {
  return mAutoMode ? 0 : mCurrentLevel
}

Inline Temp

final the local var then inline it

Replace Temp with Query

ex: local -> final -> local temp => inline temp

Introduce Explaining Variable

利用 declare var 來介紹複雜的運算式
其實常常也可以用 extract method 就好了

Split Temporary Variable

abt split…
當 var 被賦予超過一次值,結果具有多重意義時 (neither loop var nor collecting temp var)
[按] 一個暫時變數只有一種目的

Remove Assignments to Parameters

abt remove value assignment..
避免混淆 pass by value and pass by reference
Java沒有pass by reference呀!!所以像在Java,多餘的賦值動作沒有意義.

Replace Method with Method Object

turn method to object..
當 local var 氾濫又無法簡單分解的時候,把需要整理的區塊以物件 (class object) 的方式重新詮釋。 同樣的,可以使用 final var first 的方式,再用 (class object).compute() 去做簡化處理。
[按] 讓冗長的程式更清晰在做什麼
[按] 似乎可以達到意料外的效果!

Substitute Algorithm

如同字面敘述,舉例是利用 List 簡化迴圈中的多個 if。
[按] 可試。

Moving Features Between Objects

To make sure if the class is ‘Responsible’

Move Method/Field

當某 函式/欄位 在另一class更廣泛的被引用時,是否因為責任歸屬不清?
* move field 的時候注意 Self Encapulate: Replace Local Var with Query
* Self Encapulate 可以確保不出錯地保持小步前進

Extract Class

就是一個精簡提煉 Class 的手法,需要思考的點在於是否讓新的 class 曝光:
reference object or immutable value object ?

Written with StackEdit.

1/05/2017

Voice Recognize : Amazon, Google, Microsoft

Begin…
Okay這就是所謂的其實也沒什麼技術可言的較細部技術比較的整理文。裡面有大量爬日本人技術文的比較結果。日本不愧是日本,文章風格跟別的國家比起來秉持著一貫的細心,什麼問題都想到了..果然是萬物都能寫成攻略的國家阿!看完他們的比較都覺得沒什麼好寫的了lol
這篇只比較了傳統Brand比較響亮的幾家,其實多研究了一下還是有其他語音服務做得滿好的公司,若改天有整理到再來更新罷。

IBM

從缺


Amazon - AWS Alexa Service


pros

  • can do search
  • can play music
  • can using music service directly
  • can set up genearl daily task
  • API opend

cons

  • Amazon hardware device needed
  • upload source to AWS platform
  • need to enable skill on another portable device first, like cell phone
  • no conversation
  • free license 1 year limited

Microsoft Azure


pros

  • work on current device

cons

  • Cognitives Service API key will be expired in few months
  • can only recognize speaking content by ourself need to design user pattern

Google Voice SpeechRecognizer / Interaction API / Cloud Speech API


SpeechRecognizer and RecognitionListener

Android API
Intro date: Long time ago (API 8)
單句語音辨識成文字
2 result receive type are available: on time(onPartialResults) / Not on time(onResults)
Sample Here Sample in Chinese Analysis fr China

pros

  • Android built-in API, should be work on current device
  • looks possible to listening to user ALL THE TIME by implement to Service class.
  • over 50 languages
  • onPartialResults has better performance then before after Cloud Speech API had introduced to public. 原本的被說幾乎不能期待 [按]
  • [Judge]:自己實際嘗試過後,結果依然很糟,依然是幾乎沒有作用。所幸「onResults」的速度還算快

cons

  • can only recognize speaking content by ourself need to design user pattern
  • onResults have to wait for more time after Cloud Speech API had introduced to public. [按]
  • 連網後辨識能力較佳 [按]
  • 時間超過就是辨識失敗
  • not intended to be used for continuous recognition, which would consume a significant amount of battery and bandwidth.

Voice Interaction API

Android API
Intro date: 2015 Google I/O
連續聆聽的對話功能

pros

  • can do all you can do by Google search bar
  • can do conversation
  • match with Android System well, easy for development
  • has basic command pattern

cons

  • Google App license needed
  • only System built-in command are available for inner App

Cloud Speech API Beta

Google Cloud Platform API
Intro date: 2016
two mode: non-streaming / streaming (just like SpeechRecognizer)
using wave file if needed

pros

  • 辨識度高(使用machine learning) [Youtube]
  • over 80 languages
  • allow noisy environment

cons

  • 辨識時間時限(最多)1分鐘
  • non-streaming mode 的結果取得需要等待
  • 50 times for one day if free version (might be less then 50 times)

Written with StackEdit.

Voice Recognize : Amazon's Alexa vs Google Voice Assistant

Begin…
維持一個紀錄式的tech diary好困難(根本變成了yearly record)
為了不讓這個blog荒廢的太誇張,只好把工作時紀錄用的markdown拿來塞一塞了
markdown真是個好用的東西
光是清楚快速的條列筆記就已經讓人忘了blog這個東西
已經記不清楚之前在這裡寫過了些什麼,好像dump analysis寫到一半的樣子?(汗)
Anyway前陣子因為工作需要稍微研究了一下現今主要幾間公司的語音辨識應用成果和概況,這裡開始會分成兩篇來PO:「Amazon’s Alexa vs Google Voice Assistant」 & 「Amazon, Google, Microsoft」。前者是資料整理,幫助了解整個概況,後者是較細部的技術比較(也沒多技術)。整個研究完並實作了技術難度最低的離線語音辨識以後我只能說…siri真是太聰明了XD

OK首先是第一篇「Amazon’s Alexa vs Google Voice Assistant」


Amazon Alexa


Start

Use Alexa Skills Kit to teach Alexa new skills?

Build a Trivia Skill in under an Hour

Learn how to program for Alexa Platform.
Creating a solid Voice User Interface (VUI), understanding the Alexa platform, how to interact with it and certifying your skill all need to be mastered in addition to actually programing your skill in Node.js, Python, Java or whatever your favorite language may be.

Intent Schema

See Here

AWS Account

Now Using Basic Account

Limited

Invocation Name
One-word invocation names are not allowed, unless the invocation name is unique to your brand/intellectual property.

No Interaction
Cannot start conversation with Voice App.

Short Conclusion

  1. 應對pattern要上他們platform去定義(Intent Schema),這對某些人力不足(?)的開發商而言算是節省了一些時間,intent schema的增減因為不算是hardcode,也還算不那麼死板,當然這是考慮產品線單一特徵的話。
  2. 使用者必須在paired device (phone or tablet etc)上個別去做enable的動作,這點我覺得還滿annoyed的
  3. 就我實際玩過Alexa的感受來說,最大的硬傷還是在收音問題。Alexa常常聽不到我講話,或是wake up以後收音並不清楚。辨識度上跟google比還是有些距離。

Google Voice Assitant


Google Voice API

Voice Interaction API allows apps ask follow-up questions.
Communicate by intent.

  • System Voice Actions
  • Custom Voice Actions

*Voice Action

=> http://g.co/VoiceActions

*Google Search for Developers

=> http://g.co/DeveloperSearch

*CodeLab

=> http://g.co/dev/codelab-voice-interaction

Google Cloud Speech API

Convert audio to text by applying powerful neural network models.

Firebase App Indexing

Link Url with pointed App page. => [Here]

? Does it send params to App and allow it perform advanced action, too?

[ref#1] Receive search from Google Now
[ref#2] Use Voice Search to integrate with Google Now
[ref#3] Voice Search in App

Short Conclusion

G家提供的服務真是多到我看得頭昏眼花,尤其這裡的資料目前為止是研究到2016/11的部份,CloudPlatform的服務在12月之後似乎又有了新的release,但可以想見的是G家的服務發展空間極大,只是該怎麼實際帶起語音的風潮可能還需要一些時間

  1. 允許互動。雖然照理說Android 6.0就行了,但我手上的6.0怎麼行不起來= =。指令內容完全照著 I/O event 走,還是沒有反應。 但話雖如此,可以肯定的是我們已經可以輕易地透過「OK, Google」喚起自家服務,就算開放的interaction還不夠成熟(還是我的機子是假6.0…這有可能嗎= =?),要透過自己硬刻來做簡單的互動也不是不可能。 不管如何,在互動模式上跟A家比起來,G家留給開發者整個架構更大的發揮空間。
  2. 服務種類眾多。簡單來說包括了online/offline/cloud,這個在下一篇會做比較詳細的紀錄。

Written with StackEdit.