如何追加.wav格式的声音给对方 [英] How to append .wav format sounds to each other

查看:115
本文介绍了如何追加.wav格式的声音给对方的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我学习C#我自己读一些书,看一些教程。于是,我决定做一个小项目的同时,获得更多的经验和强化我的知识。我想创建一个文本语音程序在格鲁吉亚(我的语言)。我已经做了在Java中相同的程序,但要在C#中转移,但我不知道如何添加不同的声音每个other.For例如,当我的程序想要说的一句话一般是分词部分这样的GE诚为先呢 - 第二RA - 第二L - 第二(这些第一和第二意味着部分是关于这个词的第一部分,我这样做是因为GE-第一和GE - 第二有不同的语调),所以,我已经记录在.wav格式这些部分,并希望该计划追加它们,并创建一个字。我找了班MSDN.COM,发现声音播放,但我无法弄清楚如何追加的WAV格式的声音给每个-等。我想一个声音添加到另一个玩一个新的,比如我有声音说,AAA,另一个说BBBB我希望得到一个声音说:aaabbbb。

I am studying C# by myself by reading some books and watching some tutorials. So, i decided to make a small project at the same time, to get more experience and harden my knowledge. I am trying to create a text to speech program in Georgian(my language). I have done the same program in java but want to transfer it in C#, but i couldn't understand how to append different sounds to each other.For example, when my program wants to say a word "general" it divides the word in parts like this "ge"-first "ne"-second "ra"-second "l"-second (these first and second mean that the part is on the first part of the word, i did so because ge-first and ge-second have different intonations) so, i have recorded these parts in .wav format and want the program to append them and create a word. I looked for classes on MSDN.COM and found SoundPlayer but, i couldn't figure out how to append the sounds of WAV format to each-other. i want to add one sound to another and play a new one, for example i have sound that says "aaa" and the other says "bbbb" i want to get a sound that says "aaabbbb".

要分的话我创建了一个ArrayList和使用这种code。

To divide words i created an arraylist and used this code.

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;
}

我用同样的code。在我的Java程序(Java语法,当然),但试图与.wav文件的工作,当我的问题,我不知道用哪种方法和如何坚持这些声音。 这是我做的java的。

i used the same code in my java program(in java syntax, of course), but i got to the problem when trying to work with the .wav files, i don't know which method to use and how to stick these sounds. this is how i did it on java.

public AudioInputStream find(String s) throws UnsupportedAudioFileException, IOException {
         return AudioSystem.getAudioInputStream(
           new File("C:/Users/Vato/Desktop/Programing/sintezatori/alphabet/"+s+".wav"));
 }
 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;
 }

现在我想要做的几乎是同样的事情在C#。 我望着这个网页。 http://msdn.microsoft.com/ EN-US /库/ system.media.soundplayer.aspx 但无法弄清楚该怎么做,所以请帮助我:) 我应该使用怎样的方法是什么?

now i want to do almost the same thing on C#. i looked at this page http://msdn.microsoft.com/en-us/library/system.media.soundplayer.aspx but couldn't figure out what to do, so please help me :) what method should i use and how?

推荐答案

这里有很大的联系,以帮助:

here are great links to help:

  • Concatenating Wave Files Using C# 2005
  • C# WAV file class, audio mixing, and some light audio manipulation

和也许这个:合并在C#中 WAV文件

and maybe this: Merge WAV files in C#

这篇关于如何追加.wav格式的声音给对方的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆