コード例 #1
0
        private string CreateAudio(int j, AnkiItem item, string type)
        {
            const string audioTemplate = "[sound:{0}]";
            const string filePrefix    = "DeckHelper-";

            string      textField   = MediaInfo.FrontTextField;
            string      audioField  = MediaInfo.FrontAudioField;
            CultureInfo cultureInfo = MediaInfo.FrontCultureInfo;

            if (type == "B")
            {
                textField   = MediaInfo.BackTextField;
                audioField  = MediaInfo.BackAudioField;
                cultureInfo = MediaInfo.BackCultureInfo;
            }

            if (textField == null || audioField == null || cultureInfo == null)
            {
                return(String.Empty);
            }

            SynthetizerHelper.CreateAudio(Path.Combine(_path, j.ToString()),
                                          GeneralHelper.ProcessString(item[textField].ToString()), cultureInfo, MediaInfo.Bitrate);

            var fileName = filePrefix + DateTimeOffset.UtcNow.ToUnixTimeMilliseconds() + MediaInfo.Extension;

            int indexOfAudioField = Array.IndexOf(item.Keys.ToArray(), audioField);

            if (indexOfAudioField != -1)
            {
                item.Set(audioField, String.Format(audioTemplate, fileName));
            }

            return(fileName);
        }
コード例 #2
0
        private void CreateMediaFile()
        {
            string mediaFilePath = Path.Combine(_path, "media");

            if (File.Exists(mediaFilePath))
            {
                File.Delete(mediaFilePath);
            }

            using (FileStream fs = File.Create(mediaFilePath))
            {
                string data = "{";
                int    i    = 0;

                if (_mediaInfo != null)
                {
                    foreach (var item in _ankiItems)
                    {
                        if (_mediaInfo.extension == ".gif" && _mediaInfo.cultureInfo.Name == "zh-CN")
                        {
                            StrokeOrderHelper.DownloadImage(Path.Combine(_path, i.ToString()), item[_mediaInfo.field].ToString());
                        }
                        else if (_mediaInfo.extension == ".wav")
                        {
                            SynthetizerHelper.CreateAudio(Path.Combine(_path, i.ToString()), item[_mediaInfo.field].ToString(), _mediaInfo.cultureInfo, _mediaInfo.audioFormat);
                        }

                        data += "\"" + i.ToString() + "\": \"" + item[_mediaInfo.field] + _mediaInfo.extension + "\"";

                        if (i < _ankiItems.Count() - 1)
                        {
                            data += ", ";
                        }

                        i++;
                    }
                }
                data += "}";

                byte[] info = new UTF8Encoding(true).GetBytes(data);
                fs.Write(info, 0, info.Length);
                fs.Close();
            }
        }
コード例 #3
0
ファイル: Anki.cs プロジェクト: CleverCompiler/AnkiSharp
        private void CreateMediaFile()
        {
            string mediaFilePath = Path.Combine(_path, "media");

            if (File.Exists(mediaFilePath))
            {
                File.Delete(mediaFilePath);
            }

            using (FileStream fs = File.Create(mediaFilePath))
            {
                string data = "{";
                int    i    = 0;

                if (_mediaInfo != null)
                {
                    foreach (var selectedWord in _ankiItems)
                    {
                        SynthetizerHelper.CreateAudio(Path.Combine(_path, i.ToString()), selectedWord[_mediaInfo.Value.field].ToString(), _mediaInfo.Value.cultureInfo);

                        data += "\"" + i.ToString() + "\": \"" + selectedWord[_mediaInfo.Value.field] + ".wav\"";

                        if (i < _ankiItems.Count() - 1)
                        {
                            data += ", ";
                        }

                        i++;
                    }
                }
                data += "}";

                Byte[] info = new UTF8Encoding(true).GetBytes(data);
                fs.Write(info, 0, info.Length);
                fs.Close();
            }
        }