算法和封装反复修改声音对于某些持续时间的间距 [英] Algorithm and package to modify the pitch of the sound for certain durations repeatedly

查看:181
本文介绍了算法和封装反复修改声音对于某些持续时间的间距的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要创建使用现有的音频文件由我可以修改音频文件的持续时间不同的音高的音频文件。就像如果该文件是36微秒的话,我想修改一些价值1日2秒的音调,然后从6秒至9秒一些其他的价值等。

I want to create an audio file using the existing audio file by which I can modify the pitch of the audio for different durations of the file. Like if the file is of 36sec then I want to modify the pitch for 1st 2 sec with some value then from 6th sec to 9th sec some other value and so on ..

基本上,我想基于文本的消息,用户给喜欢说,如果用户输入杀死比尔,根据该消息K每一个字符,I,L,B ..我已经采取措施来修改音频文件存储不同的持续时间和喜欢我有26字母A,b,C,D ......等表的数组。基于这些持续时间,我试图修改这些特定的持续时间的文件。该问题是,我真的没有一个很好的动手在音频和我甚至尝试洞Java中的相同,但未能如愿左右。

Basically, I am trying to modify the audio file based on the text message that user gives like say if user inputs "kill bill" , according to each character in the message k,i,l,b .. i have taken an array which stores different durations and like that I have the table for 26 alphabets a,b,c,d,... and so on. Based on these durations, I am trying to modify the file for these particular durations.. the issue is that I don't really have a very good hands-on over the audio and I even tried dong the same in java but unable to do so.

如果任何人都可以认为是可以改变的音频文件未做太大变化显着其他一些参数...建议是欢迎。

If anyone could suggest some other parameter that could be changed audio file without making the change much noticeable... suggestions are welcome.

我指的是这些价值。虽然code是在Java中,但只是忽略了..我会稍后变换蟒蛇..
值以毫秒为单位
    公共静态无效convertMsgToAudio(弦乐味精){

I am referring to these values .. although the code is in java but just ignore that .. i will transform that later in python .. values are in milliseconds public static void convertMsgToAudio(String msg){

        int len = msg.length();
        duration = new double[len];
        msg = msg.toUpperCase();
        System.out.println("Msg 2 : " + msg);

        int i;
        //char ch;
        for(i=0;i<msg.length();i++){

            if(msg.charAt(i) == 'A'){
                duration[i] = 50000;
            }
            else if (msg.charAt(i) == 'B'){
                duration[i] = 100000; // value in milliseconds 
            }
            else if (msg.charAt(i) == 'C'){
                duration[i] = 150000;
            }
            else if (msg.charAt(i) == 'D'){
                duration[i] = 200000;               
            }
            else if (msg.charAt(i) == 'E'){
                duration[i] = 250000;
            }
            else if (msg.charAt(i) == 'F'){
                duration[i] = 300000;
            }
            else if (msg.charAt(i) == 'G'){
                duration[i] = 350000;
            }
            else if (msg.charAt(i) == 'H'){
                duration[i] = 400000;
            }
            else if (msg.charAt(i) == 'I'){
                duration[i] = 450000;
            }
            else if (msg.charAt(i) == 'J'){
                duration[i] = 500000;
            }
            else if (msg.charAt(i) == 'K'){
                duration[i] = 550000;
            }
            else if (msg.charAt(i) == 'L'){
                duration[i] = 600000;
            }
            else if (msg.charAt(i) == 'M'){
                duration[i] = 650000;
            }
            else if (msg.charAt(i) == 'N'){
                duration[i] = 700000;
            }
            else if (msg.charAt(i) == 'O'){
                duration[i] = 750000;
            }
            else if (msg.charAt(i) == 'P'){
                duration[i] = 800000;
            }
            else if (msg.charAt(i) == 'Q'){
                duration[i] = 850000;
            }
            else if (msg.charAt(i) == 'R'){
                duration[i] = 900000;
            }
            else if (msg.charAt(i) == 'S'){
                duration[i] = 950000;
            }
            else if (msg.charAt(i) == 'T'){
                duration[i] = 1000000;
            }
            else if (msg.charAt(i) == 'U'){
                duration[i] = 1100000;
            }
            else if (msg.charAt(i) == 'V'){
                duration[i] = 1200000;
            }
            else if (msg.charAt(i) == 'W'){
                duration[i] = 1300000;
            }
            else if (msg.charAt(i) == 'X'){
                duration[i] = 1400000;
            }
            else if (msg.charAt(i) == 'Y'){
                duration[i] = 1500000;
            }
            else if (msg.charAt(i) == 'Z'){
                duration[i] = 1600000;
            }

        }

    }

现在,我试图做同样的蟒蛇。普莱斯帮助..我很新的这概念,但我想我尝试新的东西应该始终被鼓励。

Now, I am trying to do the same in python . Pleas help.. I am very new to this concept but I think I am trying something new which should always be encouraged.

这是我第一次用这个概念面临如此多的问题..所以,请帮助。

This is the first time I am facing so many issues with this concept .. so, Please help.

推荐答案

一个简单的方法就是直接原始的PCM数据工作;这种格式的音频数据(假设16位有符号,单声道)定期(例如44100Hz)。采样的存储为每一输入2个字节-32768 ... 32767值只是一个序列

A simple way is to work on raw PCM data directly; in this format the audio data is just a sequence of -32768...32767 values stored as 2 bytes per entry (assuming 16-bit signed, mono) sampled at regular intervals (e.g. 44100Hz).

要改变你可以读这个数据的速度快如球场在45000Hz或43000Hz,这是很容易与重新采样过程完成。例如:

To alter the pitch you can just "read" this data faster e.g. at 45000Hz or 43000Hz and this is easily done with a resampling procedure. For example

 import struct
 data = open("pcm.raw", "rb").read()
 parsed = struct.unpack("%ih" % (len(data)//2), data)
 # Here parsed is an array of numbers

 pos = 0.0     # position in the source file
 speed = 1.0   # current read speed = original sampling speed
 result = []

 while pos < len(parsed)-1:
     # Compute a new sample (linear interpolation)
     ip = int(pos)
     v = int(parsed[ip] + (pos - ip)*(parsed[ip+1] - parsed[ip]))
     result.append(v)

     pos += speed     # Next position
     speed += 0.0001  # raise the pitch

 # write the result to disk
 open("out.raw", "wb").write(struct.pack("%ih" % len(result)), result)

然而

这是一个非常非常简单的方法解决问题,注意例如,增加间距将缩短长度,以避免需要这种更复杂的数学不仅仅是插值。

This is a very very simple approach to the problem, note however for example that increasing the pitch will shorten the length, to avoid this more sophisticated math is needed than just interpolating.

我用这个方法,例如通过一个音调歌在其长度提高(我想看看这是否是引人注目......它不是)。

I used approach this for example to raise by one tone a song over its length (I wanted to see if this was noticeable... it isn't).

这篇关于算法和封装反复修改声音对于某些持续时间的间距的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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