2012年3月1日 星期四

How to make corpus for HTS training ?

錄音腳本(須包含到 105 Phoneme)  音素統計程式?

安裝CoolEdite軟體作為錄製語者音訊與切音
(手動切音)使用CoolEdite手動設定字元時間資訊,用滑鼠在語音訊號上拉出字元訊號範圍,此時呈現反白(點擊右鍵選取Add to Cue List),在View工具欄可開啟Cue List選項。CoolEdite會自動將每個字元的時間長度資訊嵌入wav檔內。它會將Cue List的資訊嵌入在wav的未端,cue為list資訊的起始點。(使用UltraEdit 17.X 工具開啟:它可以將資料轉成十六進位檢視)

由於HTS訓練語料須是raw檔,因此須將錄製剪裁好的wav檔的前44byte的音檔資訊給去除掉,詳細內容請參考 https://ccrma.stanford.edu/courses/422/projects/WaveFormat/
以及cue以後的字元時間資訊也刪除!
作法如下:
1.須先製作bat檔
安裝好Microsoft Visual Studio 2008,開啟Wav2Raw專案,可直接點選Wav2Raw.sln便會自動開啟匯入(如果只有單一文件(wav2raw.c),可先建立一空專案,然後加入wav2raw.c進行compile後便會產生wav2raw.bat)
fprintf(fp,"sox -c 1 -s -2 -t wav -r 16000 CMICSD_athena_sen000%d.wav -c 1 -s -2 -t raw -r 16000 CMICSD_athena_sen000%d.raw\n",match[i][0],match[i][0]);
16000 is Sample Rate.
CMICSD_athena_sen000%d.wav is your wav files name.
CMICSD_athena_sen000%d.raw is your raw files name.
num=1; is number of  your corpus.

---------------- wav2raw.c --------------------------

#include <stdio.h>
#include <stdlib.h>


int main(){
   FILE *fp;

   int i;
   int num;
   int match[50][2]={
{6,1},
{7,1},
{8,1},
{34,2},
{49,2},
{51,2},
{63,2},
{85,2},
{112,3},
{121,3},
{257,3},
{306,3},
{344,3},
{350,3},
{371,3},
{493,3},
{613,3},
{624,3},
{674,3},
{728,3},
{745,3},
{850,3},
{940,3},
{944,3},
{974,3},
{984,3},
{1048,4},
{1049,4},
{1072,4},
{1309,4},
{1418,4},
{1432,4},
{1540,4},
{1688,4},
{1751,4},
{1815,4},
{1893,4},
{1968,4},
{2025,4},
{2135,4},
{2150,4},
{2179,4},
{2336,4},
{2355,4},
{2377,4},
{2422,4},
{2449,4},
{2474,4},
{2638,4},
{2858,4}
};

   fp = fopen("wav2raw.bat","w");

   num=1;
   for(i=0;i<num;i++){
      switch(match[i][1]){
         case 1:{
fprintf(fp,"sox -c 1 -s -2 -t wav -r 16000 CMICSD_athena_sen000%d.wav -c 1 -s -2 -t raw -r 16000 CMICSD_athena_sen000%d.raw\n",match[i][0],match[i][0]);
            break;  
         }
         case 2:{
fprintf(fp,"sox -c 1 -s -2 -t wav -r 16000 CMICSD_athena_sen00%d.wav -c 1 -s -2 -t raw -r 16000 CMICSD_athena_sen00%d.raw\n",match[i][0],match[i][0]);
            break;  
         }
         case 3:{
fprintf(fp,"sox -c 1 -s -2 -t wav -r 16000 CMICSD_athena_sen0%d.wav -c 1 -s -2 -t raw -r 16000 CMICSD_athena_sen0%d.raw\n",match[i][0],match[i][0]);
            break;  
         }
         case 4:{
fprintf(fp,"sox -c 1 -s -2 -t wav -r 16000 CMICSD_athena_sen%d.wav -c 1 -s -2 -t raw -r 16000 CMICSD_athena_sen%d.raw\n",match[i][0],match[i][0]);
            break;  
         }
         default:{
            break;      
         }
      }
   
   

   }
 
   fclose(fp);
   system("pause");
   return 0;  
}
-------------------------------------------------------------------------------
2.下載安裝sox
http://sox.sourceforge.net/
須在變數環境>>編輯>>Path中加入;C:\sox-14-3-2\
開啟cmd ,輸入sox 測試是否OK!
將wav2raw.bat與語料(wav檔)放在相同資料夾下,點擊wav2raw.bat便會自動跳出黑窗產生raw檔於資料夾中!


genLabelFromCueWaveWithPhonemePercentage 



說明:將切音之wav檔轉為mono & full-context labels,作為HTS訓練用之資料
使用方法

檔案
描述
主要輸入
input.txt cue_wave資料夾
語料切音後的wav
text.txt
語料切音後的wav檔之語意的文字
input.txt
configure檔,可由gen input.txt資料夾內程式產生
次要輸入
consonant_mean.txt
TH-CoSS語料之initial比例統計結果?
lexicon_toneModify_v6.tbl
文字分析器所需之字典檔
punctuation.tbl
文字分析器所需之符號檔
輸出
mono資料夾(要先建立)
輸出之mono label
full資料夾(要先建立)
輸出之full-context label
提醒:為HTS訓練用之資料,由於是在windows下產生,必須將產生出來mono & full labels
裡面得空白格式轉換成unix。
法一(在windows下轉換):開啟notepad++ 編輯>格式轉換>unix格式
法二(在ubuntu下轉換):使用flip:windows換行符號0D0A改為unix換行0A >>flip -u *.lab
並將wav檔使用sox工具:http://sox.sourceforge.net/,轉為raw








合成階段

C_TTS_1.06 project

說明:新版文字分析器(Cloud)+新版model+hts_engine_1.06之語音合成程式

-----文字分析器----------------


analysis.c .h
component.c
graph.c
label.c
partOfSpeechBigram.h
syllable.h
wordHashTable.h
-----------------------------------------








2012年2月27日 星期一

Android AsyncTask note

Introduction

Andr​​oid應用程式中常會遇到需要耗時執行的時候(下載音樂),因此我們會將這部分的工作安排在背景後面工作,以免造成使用者還須等待下載工作完成後才能繼續執行其他操作,一般作法都會使用Thread、 Handler。
Android為了降低開發上的難度,提供了AsyncTask供開發者方便使用。 AsyncTask就是一個封裝過的後台任務類,稱為"異步任務"。AsyncTask 讓我們可以在UI thread(使用者介面執行緒,也就是你手機應用程式畫面所看到的)中執行非同步工作。它在worker thread中執行需耗時的工作,然後將結果傳回使用介面緒,省掉我們處裡 Thread、 Handler的麻煩。


Application
常見的有上傳下載圖片音樂,當我們在一邊瀏覽音樂目錄,有一邊下載想要音樂時。
解決Intent回傳於onActivityResult方法中無法顯示提醒視窗或等待視窗(如 ProcessDialog等)。

Overview

建立一個內部類繼承AsyncTask 類別,宣告子類別時指定所使用的三個泛型參數的類別,

Params,Progress和Result。

AsyncTask<Params, Progress, Result>,實作時定義參數型態,

Params 啟動任務執行的輸入參數,如HTTP請求的URL。
Progress 後台任務執行的百分比。
Result 後台執行任務最終返回的結果,如String。

例如AsyncTask< Integer , Integer , String >
Params為Integer ; Params為Integer ;  Result 為String
AsyncTask<Integer, Integer, String>
第一個參數對應呼叫execute()和doInBackground()的參數,不故定數目的參數,可以是陣列。
第二個參數對應呼叫publishProgress()和onProgressUpdate()的參數, 不故定數目的參數,可以是陣列 。
第三個參數對應doInBackground()的回傳值和onPostExecute()的呼叫參數。

生命週期:
1. execute() :於UI Tread啟動任務
2. onPreExecute() : 任務開始
3. doInBackground() : 在背景執行緒池,執行主要的背景工作,自動在worker thread中執行。可隨時呼叫 publishProgress() 來執行介面緒的 onProgressUpdate()更新介面進度。doInBackground() 的傳回值會傳給 onPostExecute()。
4. onProgressUpdate() :獲取資料即時在介面上更新
5. onPostExecute() : 任務結束
onPreExecute(), onPostExecute(), 和 onProgressUpdate() 都在介面緒執行(不直接呼叫也不可手動呼叫)。

PS:記得處理工作緒的意外重新啟動,例如使用者旋轉螢幕等。
http://changxianli6121.blog.163.com/blog/static/56392130201042712956597/
http://neurosoft.blogspot.com/2011/11/android-threads-handlers-and-asynctask.html
http://developer.android.com/reference/android/os/AsyncTask.html
http://zjf1428.iteye.com/blog/919066

以下code為一開始跳出等待視窗,等待進度bar完成後,等待視窗便消失!
--------------------------------------------------------------------------------------------------------
public class AsyncTask1Activity extends Activity {
    /** Called when the activity is first created. */

private ProgressBar pBar;

@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
   
        pBar = (ProgressBar) findViewById(R.id.progress_bar);
    //AsyncTask.execute()要在主線程調用
    new AsyncLoader().execute(0);
    }

  //AsyncTask
  // 設置三種參數分別是<Integer,Integer,String> ,對應著
  // doInBackground(Params),onProgressUpdate(Progress),onPostExecute(Result)參數
  class AsyncLoader extends AsyncTask<Integer, Integer, String>{


private ProgressDialog pdg = null;
@Override
protected String doInBackground(Integer...integers) {
// TODO Auto-generated method stub
          Log.d("TAG", "doInBackground()");
     
          for (int i=integers[0]; i <= 100;i+=10) {
              publishProgress(i);
              try {
                  Thread.sleep(500);
              } catch (InterruptedException e) {
                  e.printStackTrace();
              }
          }
          return null;
}

@Override
protected void onPreExecute() {
// TODO Auto-generated method stub
super.onPreExecute();
//任務執行前
Log.d("TAG", "onPreExecute");
pdg = ProgressDialog.show(AsyncTask1Activity.this,"please wait...","Android accessing",true);
}


@Override
protected void onProgressUpdate(Integer... progress) {
// TODO Auto-generated method stub
super.onProgressUpdate(progress);
//任務執行中UI上進度更新
Log.d("TAG", "onProgressUpdate");
pBar.setProgress(progress[0]);
}

@Override
protected void onPostExecute(String result) {
// TODO Auto-generated method stub
super.onPostExecute(result);
//任務執行後
Log.d("TAG", "onPostExecute");
pdg.dismiss();
}

@Override
protected void onCancelled() {
// TODO Auto-generated method stub
super.onCancelled();
Log.d("TAG", "onCancelled");
}
  }
}







2012年2月26日 星期日

A bug in Reminder System V1.O

Bug-若手機有開啟自動旋轉螢幕設定,在本系統橫像掃描條碼後,再垂直觀看手機掃描分析後結果,可能會遇到無法獲得掃描結果(畫面跟掃)。

原因出在-自動旋轉螢幕會造成重新啟動該Activity,造成畫面無法更新分析後資訊在該Activity上,於AndroidManifest.xml中<activity>標籤中加入 android:screenOrientation="portrait"屬性,portrait為只能垂直螢幕觀看,landscape只能水平螢幕觀看。

一般來說,Android每次螢幕的切換動會重啟(on Restart)Activity,所以Activity銷毀(on Destroy)前會保存當前活動的資訊,等Activity再次on Create的時候載入資訊配置。
若Activity加上android:configChanges="keyboardHidden|orientation"屬性,就會停止重新啟動Activity.而是去調用public void onConfigurationChanged (Configuration newConfig)
因此我們可以在不用重新啟動Activity下調整顯示方式。

http://developer.android.com/guide/topics/manifest/activity-element.html#screen
http://developer.android.com/guide/topics/manifest/activity-element.html#config

2012年2月24日 星期五

Training HTS demo make new TTS model


cd 目錄到 "HTS-demo_NIT-ATR503-M001"
隨著訓練語料的多寡,必小心電腦的記憶體大小,否則會造成訓練不出model情況!
以清大語料來看記憶體要大於2G以上比較好

將北京清大語料data取代HTS-demo_NIT-ATR503-M001的data,並到raw資料夾檢查語料是否含有日文資料,如有請重新刪除,假如一時疏漏已經執行到make階段,終止程序(Ctrl+C)並且make clean清除以編譯好的文件,
make distclean   把./configure產生的文件刪掉,若要回復configure文件請輸入步驟(3) setting path的指令
ps 顯示背景工作程序

(1)執行"make clean" 與 "make distclean"

(2) "HTS-demo_NIT-ATR503-M001資料夾下 open  "configure.ac"  modify like those ,finally save.
修改參數時請用手打,避免到格行
------------------------------------------------------------------------------
#語料設定
#一般語料如"th_cross_female_sen0001.raw"
# speaker and dataset names

if test -z "$SPEAKER"; then
SPEAKER=female
fi

if test -z "$DATASET"; then
DATASET=th_coss
fi

#由於HTS語料的sample rate is 44kHz,而我們使用的為16Hz因此需要修改音框大小移
#動量等設定

# default values
if test -z "$FRAMELEN"; then
FRAMELEN=400
fi

if test -z "$FRAMESHIFT"; then
FRAMESHIFT=80
fi

if test -z "$WINDOWTYPE"; then
WINDOWTYPE=1
fi

if test -z "$NORMALIZE"; then
NORMALIZE=1
fi

if test -z "$FFTLEN"; then
FFTLEN=512
fi

if test -z "$SAMPFREQ"; then
SAMPFREQ=16000
fi

#HMM模型的參數設定或修改如下

if test -z "$MGCORDER"; then
if test $GAMMA -eq 0; then
MGCORDER=24
else
MGCORDER=12
fi
fi


if test -z "$LOWERF0"; then
LOWERF0=80
fi

if test -z "$UPPERF0"; then
UPPERF0=350
fi
------------------------------------------------------------------------------

(3) setting path 產生
configure: creating ./config.status
config.status: creating data/Makefile
config.status: creating scripts/Config.pm
config.status: creating Makefile

./configure --with-tcl-search-path=/opt/ActiveTcl-8.4/bin --with-sptk-search-path=/usr/local/SPTK/bin --with-hts-search-path=/usr/local/HTS-2.2beta/bin --with-hts-engine-search-path=/usr/local/bin


(4)"HTS-demo_NIT-ATR503-M001資料夾下 open  "configure"  modify like step (1) ,finally save.

(5) make

跑完後model會放在voice>qst0001>ver1




Nomachine



1,根據自己的電腦5.3下載相應的Nomachine NX的包(我的Ubuntu的系統是amd64bit

wget http://64.34.161.181/download/3.5.0/Linux/nxclient_3.5.0-7_amd64.deb 
wget http://64.34.161.181/download/3.5.0/Linux/nxnode_3.5.0-7_amd64.deb 
wget http://64.34.161.181/download/3.5.0/Linux/EDS/nxserver_3.5.0-9_amd64 



2,安裝nxnodenxservernxclient依次進行安裝
sudo dpkg -i nxnode_3.5.0-7_amd64.deb nxserver_3.5.0-9_amd64 nxclient_3.5.0-7_amd64.deb


3.NX需要連接SSH22端口,所以要先安裝SSH
sudo apt-get install openssh-server openssh-client 


4。安裝FreeNX服務
nomachine什麼商業軟件,只有客戶端(客戶端)什麼免費的!所以我們當前需要安裝FreeNX服務

http://pachiratech-yuan.iteye.com/blog/1068094

sudo add-apt-repository ppa:freenx-team


sudo apt-get update
sudo apt-get install freenx

2012年2月22日 星期三

安裝Ubuntu 須做的幾件事

在安裝完成後的Ubuntu,所有的線上更新與套件下載都須透過內部設定好的Mirror Server,台灣區的伺服器是tw.archive.ubuntu.com常常出現掛點情況,如果在升級或下載套件時出現套件相依性無法解析問題(常見的有在中文化過程安裝不完整),大多數原因出在於tw.archive.ubuntu.com已不支援此套件或是Server出了問題,為了方便解決建議您將Mirror site換成Ubuntu主要的Server(archive.ubuntu.com)
關於更換Mirror Server方法說明如下
收尋”Software sources”

將伺服器更換為「主要伺服器」。主要伺服器為國際Ubuntu Server 套件來源會是最新,但下載速度會稍慢。


升級你的Ubuntu軟件版本,開啟終端機輸入:
sudo apt-get update && sudo apt-get upgrade