File: UtauVoiceDB.cs

package info (click to toggle)
cadencii 3.3.9%2Bsvn20110818.r1732-6
  • links: PTS
  • area: main
  • in suites: buster
  • size: 35,916 kB
  • sloc: cs: 160,836; java: 42,449; cpp: 7,605; ansic: 1,728; perl: 1,087; makefile: 236; php: 142; xml: 117; sh: 21
file content (175 lines) | stat: -rw-r--r-- 6,549 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
/*
 * UtauVoiceDB.cs
 * Copyright © 2009-2011 kbinani
 *
 * This file is part of org.kbinani.cadencii.
 *
 * org.kbinani.cadencii is free software; you can redistribute it and/or
 * modify it under the terms of the GPLv3 License.
 *
 * org.kbinani.cadencii is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 */
#if JAVA
package org.kbinani.cadencii;

import java.util.*;
import java.io.*;
import org.kbinani.*;
import org.kbinani.vsq.*;
#else
using System;
using org.kbinani;
using org.kbinani.java.util;
using org.kbinani.java.io;
using org.kbinani.vsq;

namespace org.kbinani.cadencii {
    using boolean = System.Boolean;
#endif

    /// <summary>
    /// UTAUの原音設定を表すクラス
    /// </summary>
    public class UtauVoiceDB {
        private Vector<OtoArgs> _configs = new Vector<OtoArgs>();
        private String _name = "Unknown";

        /// <summary>
        /// コンストラクタ.
        /// </summary>
        /// <param name="singer_config"></param>
        public UtauVoiceDB( SingerConfig singer_config ) {
            _name = singer_config.VOICENAME;
            String oto_ini = fsys.combine( singer_config.VOICEIDSTR, "oto.ini" );
            readOtoIni( oto_ini );
        }

        /// <summary>
        /// 原音設定ファイルを読み込みます.
        /// </summary>
        /// <param name="oto_ini">原音設定のパス</param>
        private void readOtoIni( String oto_ini ) {
            if ( !fsys.isFileExists( oto_ini ) ) {
                return;
            }

            // oto.ini読込み
            String dir = PortUtil.getDirectoryName( oto_ini );
            foreach ( String encoding in AppManager.TEXT_ENCODINGS_IN_UTAU ) {
                BufferedReader sr = null;
                try {
                    sr = new BufferedReader( new InputStreamReader( new FileInputStream( oto_ini ), encoding ) );
                    String line;
                    while ( sr.ready() ) {
                        line = sr.readLine();
                        String[] spl = PortUtil.splitString( line, '=' );
                        if ( spl.Length < 2 ) {
                            continue;
                        }
                        String file_name = spl[0]; // あ.wav
                        String a2 = spl[1]; // ,0,36,64,0,0
                        String a1 = PortUtil.getFileNameWithoutExtension( file_name );
                        spl = PortUtil.splitString( a2, ',' );
                        if ( spl.Length < 6 ) {
                            continue;
                        }

                        // ファイルがちゃんとあるかどうか?
                        String fullpath = fsys.combine( dir, file_name );
                        if ( !fsys.isFileExists( fullpath ) ) {
                            continue;
                        }

                        OtoArgs oa = new OtoArgs();
                        oa.fileName = file_name;
                        oa.Alias = spl[0];
                        try {
                            oa.msOffset = (float)str.tof( spl[1] );
                        } catch ( Exception ex ) {
                            oa.msOffset = 0;
                        }
                        try {
                            oa.msConsonant = (float)str.tof( spl[2] );
                        } catch ( Exception ex ) {
                            oa.msConsonant = 0;
                        }
                        try {
                            oa.msBlank = (float)str.tof( spl[3] );
                        } catch ( Exception ex ) {
                            oa.msBlank = 0;
                        }
                        try {
                            oa.msPreUtterance = (float)str.tof( spl[4] );
                        } catch ( Exception ex ) {
                            oa.msPreUtterance = 0;
                        }
                        try {
                            oa.msOverlap = (float)str.tof( spl[5] );
                        } catch ( Exception ex ) {
                            oa.msOverlap = 0;
                        }

                        // 重複登録が無いかチェック
                        boolean found = false;
                        foreach ( OtoArgs o in _configs ) {
#if JAVA
                            if ( o == null ) {
                                continue;
                            }
#endif
                            if ( o.equals( oa ) ) {
                                found = true;
                                break;
                            }
                        }
                        if ( !found ) {
                            _configs.add( oa );
                        }
                    }
                } catch ( Exception ex ) {
                    //serr.println( "UtauVoiceDB#.ctor; ex=" + ex );
                } finally {
                    if ( sr != null ) {
                        try {
                            sr.close();
                        } catch ( Exception ex2 ) {
                            serr.println( "UtauVoiceDB#.ctor; ex2=" + ex2 );
                        }
                    }
                }
            }
        }

        /// <summary>
        /// 指定した歌詞に合致する、エイリアスを考慮した原音設定を取得します
        /// </summary>
        /// <param name="lyric"></param>
        /// <returns></returns>
        public OtoArgs attachFileNameFromLyric( String lyric ) {
            int count = _configs.size();
            for ( Iterator<OtoArgs> itr = _configs.iterator(); itr.hasNext(); ) {
                OtoArgs item = itr.next();
                if ( str.compare( PortUtil.getFileNameWithoutExtension( item.fileName ), lyric ) ) {
                    return item;
                }
                if ( str.compare( item.Alias, lyric ) ) {
                    return item;
                }
            }
            return new OtoArgs();
        }

        /// <summary>
        /// この原音の名称を取得します.
        /// </summary>
        /// <returns>この原音の名称</returns>
        public String getName() {
            return _name;
        }
    }

#if !JAVA
}
#endif