C# 如何在C语言中附加声音#

C# 如何在C语言中附加声音#,c#,java,.net,soundplayer,C#,Java,.net,Soundplayer,我正在通过阅读一些书籍和观看一些教程来自学C#。因此,我决定同时做一个小项目,以获得更多的经验并强化我的知识。我试图用格鲁吉亚语(我的语言)创建一个文本到语音的程序,但我不明白如何将不同的声音附加到彼此身上。例如,当我的程序想说“语言”时,它会将单词分成“la”“n”“gu”“a”“ge”,因此,我已经记录了这些部分,并希望附加它们并创建一个单词。我在MSDN.COM上查找了一些类,找到了SoundPlayer,但我不知道如何附加WAV格式的声音。我想将一个声音添加到另一个声音中,然后播放一个新

我正在通过阅读一些书籍和观看一些教程来自学C#。因此,我决定同时做一个小项目,以获得更多的经验并强化我的知识。我试图用格鲁吉亚语(我的语言)创建一个文本到语音的程序,但我不明白如何将不同的声音附加到彼此身上。例如,当我的程序想说“语言”时,它会将单词分成“la”“n”“gu”“a”“ge”,因此,我已经记录了这些部分,并希望附加它们并创建一个单词。我在MSDN.COM上查找了一些类,找到了SoundPlayer,但我不知道如何附加WAV格式的声音。我想将一个声音添加到另一个声音中,然后播放一个新的声音,例如,我有一个声音说“aaa”,另一个声音说“bbbb”,我想得到一个声音说“AAABBB”

为了划分单词,我创建了一个arraylist并使用了以下代码

public ArrayList divide(String s)  //დაყოფა და arraylist-ში გადანაწილება
    {
        ArrayList a = new ArrayList();
        int i = 0;
        while (i < s.Length)
        {
            if (s[i] == ',' || s[i] == ' ' || s[i] == '.')
            {
                a.Add(s.Substring(i, i + 1));
                i++;
                continue;
            }
            if (consonant(s[i]) && (i + 1) != s.Length && sonant(s[i + 1]))
            {
                if (isFirstSonant(s, i))
                    a.Add(s.Substring(i, i + 2) + "_FIRST");
                else
                    a.Add(s.Substring(i, i + 2) + "_SECOND");
                i += 2;
                continue;
            }
            if (sonant(s[i]) && ((i + 1) < s.Length && sonant(s[i]) || i == (s.Length - 1)))
            {
                if (isFirstSonant(s, i))
                    a.Add(s.Substring(i, i + 1) + "_FIRST");
                else
                    a.Add(s.Substring(i, i + 1) + "_SECOND");
                i++;
                continue;
            }
            if (consonant(s[i]) && ((i + 1) < s.Length && consonant(s[i]) || i == (s.Length - 1)))
            {
                a.Add(s.Substring(i, i + 1) + "_SECOND");
                i++;
                continue;
            }
        }
        return a;
    }
public ArrayList divide(字符串s)//დაყოფა და arraylist-ში გადანაწილება
{
ArrayList a=新的ArrayList();
int i=0;
而(i
我已经在java上编写了这个程序,并希望在C#上也这样做,所以这是我在java上的代码。 这就是我在后面添加声音的方式,将它们放在arraylist中

public AudioInputStream append(AudioInputStream main, String s) throws UnsupportedAudioFileException, IOException {
     return new AudioInputStream(
             new SequenceInputStream(main, find(s)),     
             main.getFormat(), 
             main.getFrameLength() + find(s).getFrameLength());
 }
 private String s;
 public void Process() {
    try {
        AudioInputStream main = AudioSystem.getAudioInputStream(new File("C:/Users/Vato/Desktop/Programing/sintezatori/alphabet/blank.wav"));
        ArrayList<String> aa = divide(s);
        for(int ii=0;ii<aa.size();ii++) {
            main=append(main, aa.get(ii));
            System.out.println(aa.get(ii));
        }
        AudioSystem.write(main, AudioFileFormat.Type.WAVE, new File("C:/Users/Vato/Desktop/Programing/sintezatori/alphabet/result.wav"));
        result=main;
        AudioInputStream result1 = AudioSystem.getAudioInputStream(new File("C:/Users/Vato/Desktop/Programing/sintezatori/alphabet/result.wav")); 
        DataLine.Info info =
            new DataLine.Info(Clip.class,
                    result1.getFormat());
        Clip clip = (Clip) AudioSystem.getLine(info);
        clip.open(result1);
        clip.start();
        } catch (Exception e) {
          e.printStackTrace();
        }
   }
 private AudioInputStream result;
 public AudioInputStream getResult() {
     return result;
 }
public AudioInputStream append(AudioInputStream main,字符串s)抛出不支持的数据文件异常,IOException{
返回新的音频输入流(
新SequenceInputStream(主,查找),
main.getFormat(),
main.getFrameLength()+查找.getFrameLength());
}
私有字符串;
公共程序(){
试一试{
AudioInputStream main=AudioSystem.getAudioInputStream(新文件(“C:/Users/Vato/Desktop/programming/sintezatori/alphabet/blank.wav”);
ArrayList aa=除数;
对于(int ii=0;ii?

如何在C#中实现同样的效果?

AT&T文本语音SDK非常出色。您可以制作自定义词典和声音。

AT&T文本语音SDK非常出色。您可以制作自定义词典和声音。

声音播放器应该可以:

using System.Media;

InitializeComponent();
Soundplayer MySounds = new SoundPlayer(@"C:\example.wav);
MySounds.Play();

声音播放器应该工作:

using System.Media;

InitializeComponent();
Soundplayer MySounds = new SoundPlayer(@"C:\example.wav);
MySounds.Play();

如果不想使用现有SDK,可以执行以下操作:

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Media;
using System.Text;

namespace ConsoleApplication3
{
    public class SpeechClass
    {

        private Dictionary<char, string> _letterToFileMapping = new Dictionary<char, string>();
        private string _basePath = "\\soundfiles";


        public SpeechClass()
        {
            PopulateMappings();
        }


        private void PopulateMappings()
        {
            _letterToFileMapping.Add('a', "asound.wav");
            _letterToFileMapping.Add('b', "bsound.wav");
            _letterToFileMapping.Add('c', "csound.wav");
            _letterToFileMapping.Add('d', "dsound.wav");
        }

        private void SayWord(string word)
        {
            var chars = word.ToCharArray();

            List<string> filestosay = new List<string>();

            foreach (var c in chars)
            {
                string sound;
                if(_letterToFileMapping.TryGetValue(c, out sound))
                {
                    filestosay.Add(sound);
                }
            }

            foreach (string s in filestosay)
            {
                SoundPlayer p = new SoundPlayer();
                p.SoundLocation = Path.Combine(_basePath, s);
                p.Play();

            }
        }
    }
}
使用系统;
使用System.Collections.Generic;
使用System.IO;
使用System.Linq;
使用系统、媒体;
使用系统文本;
命名空间控制台应用程序3
{
公开课演讲课
{
私有字典_letterfoilemapping=新字典();
私有字符串\u basePath=“\\soundfiles”;
公共演讲课
{
PopulateMappings();
}
私有void PopulateMappings()
{
_添加('a',“asound.wav”);
_添加('b',“bsound.wav”);
_添加('c','csound.wav”);
_添加('d',“dsound.wav”);
}
私有空字(字符串字)
{
var chars=word.ToCharArray();
List filestosay=new List();
foreach(以字符表示的变量c)
{
弦乐;
if(_letterofilemapping.TryGetValue(c,输出声音))
{
filestosay.Add(声音);
}
}
foreach(filestosay中的字符串s)
{
SoundPlayer p=新的SoundPlayer();
p、 SoundLocation=Path.Combine(_basePath,s);
p、 Play();
}
}
}
}

如果不想使用现有SDK,可以执行以下操作:

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Media;
using System.Text;

namespace ConsoleApplication3
{
    public class SpeechClass
    {

        private Dictionary<char, string> _letterToFileMapping = new Dictionary<char, string>();
        private string _basePath = "\\soundfiles";


        public SpeechClass()
        {
            PopulateMappings();
        }


        private void PopulateMappings()
        {
            _letterToFileMapping.Add('a', "asound.wav");
            _letterToFileMapping.Add('b', "bsound.wav");
            _letterToFileMapping.Add('c', "csound.wav");
            _letterToFileMapping.Add('d', "dsound.wav");
        }

        private void SayWord(string word)
        {
            var chars = word.ToCharArray();

            List<string> filestosay = new List<string>();

            foreach (var c in chars)
            {
                string sound;
                if(_letterToFileMapping.TryGetValue(c, out sound))
                {
                    filestosay.Add(sound);
                }
            }

            foreach (string s in filestosay)
            {
                SoundPlayer p = new SoundPlayer();
                p.SoundLocation = Path.Combine(_basePath, s);
                p.Play();

            }
        }
    }
}
使用系统;
使用System.Collections.Generic;
使用System.IO;
使用System.Linq;
使用系统、媒体;
使用系统文本;
命名空间控制台应用程序3
{
公开课演讲课
{
私有字典_letterfoilemapping=新字典();
私有字符串\u basePath=“\\soundfiles”;
公共演讲课
{
PopulateMappings();
}
私有void PopulateMappings()
{
_添加('a',“asound.wav”);
_添加('b',“bsound.wav”);
_添加('c','csound.wav”);
_添加('d',“dsound.wav”);
}
私有空字(字符串字)
{
var chars=word.ToCharArray();
List filestosay=new List();
foreach(以字符表示的变量c)
{
弦乐;
if(_letterofilemapping.TryGetValue(c,输出声音))
{
filestosay.Add(声音);
}
}
foreach(filestosay中的字符串s)
{
SoundPlayer p=新的SoundPlayer();
p、 SoundLocation=Path.Combine(_basePath,