Java如何编写128 kpbs的wav文件

时间:2016-08-10 12:02:54

标签: java audio

我正在使用marytts创建.wav个文件。

.wav个文件的kpbs根据我正在使用的语音而变化,并带有下面的代码。我想用128 kpbs写每个音频文件。

由于我计划使用生成的.wav文件并且仅支持128 kpbs的程序,有没有办法将.wav文件写入128kpbs?

这是我的代码:

AudioInputStream audio = marytts.generateAudio(text); //generate audio from text
AudioSystem.write(audio, AudioFileFormat.Type.WAVE, new File("F:\\temp\\" + filename + ".wav"));//save audio as .wav to the static location with filename
return true;//function completed so return true

1 个答案:

答案 0 :(得分:6)

我设法找到了我的问题的答案。

也许以后有人也会问同样的问题所以我会给出解决方案。

在课程下我写了这些全局变量,因为我想要我的wav

AudioFormat defaultFormat = new AudioFormat(defaultEncoding,fDefaultSampleRate,nDefaultSampleSizeInBits,nDefaultChannels,frameSize,frameRate,bDefaultBigEndian);
AudioInputStream GeneratedAudio = marytts.generateAudio(text); //generate audio from text
AudioInputStream audio = AudioSystem.getAudioInputStream(defaultFormat, GeneratedAudio);
AudioSystem.write(audio, AudioFileFormat.Type.WAVE, new File("F:\\temp\\" + filename + ".wav"));//save audio as .wav to the static location with filename
return true;//function completed so return true

并改变了我的代码。

我创建了一个我想要的格式,从文本生成音频,以我的格式更改音频并编写它。

package nl.project.webapp.config;

@Order(1)
public class AppInitializer extends AbstractAnnotationConfigDispatcherServletInitializer{

    @Override
    protected Class<?>[] getRootConfigClasses() {
        return new Class<?>[]{WebAppConfig.class};
    }

    @Override
    protected Class<?>[] getServletConfigClasses() {
        return new Class<?>[]{ServletConfig.class};
    }

    @Override
    protected String[] getServletMappings() {
        return new String[]{"/"};
    }

    [...]
}

package nl.project.webapp.config;

@Configuration
@ComponentScan(basePackages = {"nl.project.webapp"},excludeFilters={
    @ComponentScan.Filter(type=FilterType.ANNOTATION,value=Controller.class),
    @ComponentScan.Filter(type=FilterType.ANNOTATION,value=RestController.class)
})
@Import({AppConfig.class,JPAConfig.class})
@PropertySource("classpath:msa.properties")
public class WebAppConfig {
    [...]
}

package nl.project.webapp.config;

@Configuration
@EnableWebMvc
@ComponentScan(basePackages = {"nl.project.webapp.controller"},includeFilters={
    @ComponentScan.Filter(type=FilterType.ANNOTATION,value=Controller.class),
    @ComponentScan.Filter(type=FilterType.ANNOTATION,value=RestController.class)    
})
public class ServletConfig extends WebMvcConfigurerAdapter{
   [...]    
}

package nl.project.webapp.social.config;

@Configuration
public class SocialConfig{

    @Bean
    public MyConnectController connectController(MessageSource messages, UsorManager userMgr, PhotoManager photoMgr) {

        MyConnectController connectController = new MyConnectController(connectionFactoryLocator, connectionRepository);
        connectController.setConnectInterceptors(Arrays.asList(new ConnectInterceptor<?>[]{
            new TwitterConnectInterceptor(userMgr, photoMgr, messages),
            new FacebookConnectInterceptor(userMgr, photoMgr, messages),
            new LinkedInConnectInterceptor(userMgr, photoMgr, messages),
            new GoogleConnectInterceptor(userMgr, photoMgr, messages),
        }));

        return connectController;
    }

    @Bean 
    public MySignInController signinController(MessageSource messages, UsorManager userMgr, PhotoManager photoMgr){

        MySignInController signinController = new MySignInController(connectionFactoryLocator, usersConnectionRepository, new SimpleSigninAdapter(userMgr));
        signinController.setSignInInterceptors(Arrays.asList(new ProviderSignInInterceptor<?>[]{
            new FacebookSigninInterceptor(userMgr, photoMgr, messages),
            new LinkedInSigninInterceptor(userMgr, photoMgr),
            new GoogleSigninInterceptor(userMgr, photoMgr)
        }));

        return signinController;
    }

}


package nl.project.webapp.social.controller;

@Controller
@RequestMapping("/signin")
public class MySignInController extends ProviderSignInController {

    public MySignInController(
            ConnectionFactoryLocator connectionFactoryLocator,
            UsersConnectionRepository usersConnectionRepository,
            SignInAdapter signInAdapter) {
        super(connectionFactoryLocator, usersConnectionRepository, signInAdapter);
        this.connectionFactoryLocator = connectionFactoryLocator;

    }

[...]