當前位置:首頁 » 操作系統 » htk源碼

htk源碼

發布時間: 2022-03-05 16:46:57

① 語音識別sdk支持的音頻格式,采樣率有哪些

1、用audioread('');函數讀取電腦音頻文件參數音頻文件路徑:
[sampledata,FS] = audioread('F:1.mp3');
sampledata保存音頻信號數據FS音頻采率MP3格式采率般44100;

2、判斷音頻數據否雙聲道雙聲道則保留聲道數據用calsample.m文件函數完功能文件內容:

function sample = calsample(sampledata,FS)
temp_sample = resample(sampledata,1,FS/11025);
[m,n] = size(temp_sample);
if (n == 2)
sample = temp_sample(:,1);
else
sample = temp_sample;
end
end

② htk訓練gmm模型時怎麼配置proto

要看具體變數的類型,看個例子吧:
在網路游戲中,游戲玩家之間的同步是一個最基本的功能,而同步是通過對坐標的廣播進行的,因此我們假設一個簡單的模型,當一個玩家的位置發生變化時,將玩家的新位置發給地圖內所有玩家,根據這個情況寫出以下proto文件。

message PlayerPos{
required uint32 playerID = 1;
required float posX = 2 ;
required float posY = 3 ;
}
這樣就有一個問題,現在的游戲都是3D游戲,因此需要xyz來表示位置,還需要另一組xyz來表示朝向,如果用簡單變數的話就會顯的很亂,而且無論是位置還是朝向其實都是一組xyz,因此可以將xyz抽出來成為一個復合數據類型,單獨放在一個文件中。這樣就構成以下文件。

file vector.proto

message vector3D{
required float x = 1;
required float y = 2;
required float z = 3;
};

file Player.proto

import "vector.proto";

message PlayerPos {
required uint32 playerID = 1;
required vector3D pos = 2;
};

編譯的時候先編譯vector文件,採用import時需要注意路徑,本例中兩文件在同一目錄下。

protoc --cpp_out=. vector.proto Player.proto

proto對應的文件已經生成了,但是該怎麼賦值呢,查API查了半天有點不知所以,乾脆來看生成的類文件的源代碼吧

// required uint32 playerID = 1;
inline bool has_playerid() const;
inline void clear_playerid();
static const int kPlayerIDFieldNumber = 1;
inline ::google::protobuf::uint32 playerid() const;
inline void set_playerid(::google::protobuf::uint32 value);

// required .vector3D pos = 2;
inline bool has_pos() const;
inline void clear_pos();
static const int kPosFieldNumber = 2;
inline const ::vector3D& pos() const;
inline ::vector3D* mutable_pos();
inline ::vector3D* release_pos();
inline void set_allocated_pos(::vector3D* pos);

上面列出了生成的部分源代碼,主要是PlayerPos的操作變數的函數,第一個playID很簡單,可以看到直接使用set_playerid ( ) 即可,但是對於嵌套的pos 發現沒有對應的set_pos方法,不過發現了一個set_allocated_pos() 函數,這個函數也是set開頭的,看看這個函數是幹嘛的。

inline void PlayerPos::set_allocated_pos(::vector3D* pos) {
delete pos_;
pos_ = pos;
if (pos) {
set_has_pos();
} else {
clear_has_pos();
}
}

看上去可以賦值,直接調用set_allocated_pos() 進行賦值看一看

PlayerPos player;
vector3D tmp;
tmp.x = 1;
tmp.y = 2;
tmp.z = 3;
player.set_allocated_pos(&tmp)

編譯沒問題,但是運行時出現錯誤,而且是很奇怪的錯誤,仔細了查看一下PlayerPos的源碼,發現一個問題

::vector3D* pos_;
::google::protobuf::uint32 playerid_;

上面是PlayerPos中變數的保存形式,發現pos是作為一個指針存儲的,如果按照之前的賦值 tmp 是一個局部變數,函數返回時局部變數自動銷毀,而pos_保存的仍然是已被銷毀的tmp的位置,因此會出錯,如果採用new的話就可以解決這個問題,即賦值方法如下

PlayerPos player;
vector3D *tmp = new Vector3D;
tmp->x = 1;
tmp->y = 2;
tmp->z = 3;
player.set_allocated_pos(tmp)

這樣即可,編譯運行都沒有問題。

如此之外,還有一種賦值方法,就是調用mutable_pos()

inline ::vector3D* PlayerPos::mutable_pos() {
set_has_pos();
if (pos_ == NULL) pos_ = new ::vector3D;
return pos_;
}

mutable_pos () 中自己new出了一個vector3D 對象,而vector3D中又實現了賦值的重載,因此可以這樣解決

PlayerPos player;
vector3D *tmp = player.mutable_pos();
tmp->x = 1;
tmp->y = 2;
tmp->z = 3;

熱點內容
linux路由轉發 發布:2024-09-23 21:22:41 瀏覽:381
linux基金會成立 發布:2024-09-23 21:22:06 瀏覽:999
e的運演算法則 發布:2024-09-23 21:21:05 瀏覽:119
在同一路由器下如何訪問伺服器 發布:2024-09-23 20:55:41 瀏覽:556
天逸哪個配置帶電子擋桿 發布:2024-09-23 19:51:22 瀏覽:547
sqrt在c語言中什麼意思 發布:2024-09-23 19:50:04 瀏覽:507
京東羊毛伺服器搭建 發布:2024-09-23 19:33:39 瀏覽:9
伺服器的遠程埠被關了如何打開 發布:2024-09-23 18:33:22 瀏覽:230
phpjs注入 發布:2024-09-23 18:31:51 瀏覽:596
高性能php應用開發 發布:2024-09-23 18:23:56 瀏覽:209