大佬教程收集整理的这篇文章主要介绍了iOS Swift – 将.wav文件合并并转换为.mp3,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
在swift中合并两个.wav文件是没有问题的. Here is my example现在我不知道如何添加lame库来快速的项目以及如何使用它(如何改变客观的c跛脚代码使用语法,以便在swift中使用它).
我坚持在迅速,所以我尝试Lame库与Objective C.我找到了将.caf转换为.mp3的示例代码,所以我试过了.这是我试过的:
- (void) toMp3 { NSString *cafFilePath = [[NSBundle mainBundle] pathForresource:@"sound" ofType:@"caf"]; NSString *mp3Filename = @"Mp3File"; mp3Filename = [mp3Filename StringByAppendingString:@".mp3"]; NSString *mp3FilePath = [[NSHomeDirectory() StringByAppendingFormat:@"/Documents/"] StringByAppendingPathComponent:mp3Filename]; NSLog(@"%@",mp3FilePath); @try { int read,write; FILE *pcm = fopen([cafFilePath cStringUsingEncoding:1],"rb"); //source fseek(pcm,4*1024,SEEK_CUR); //skip file header FILE *mp3 = fopen([mp3FilePath cStringUsingEncoding:1],"wb"); //output const int PCM_SIZE = 8192; const int MP3_SIZE = 8192; short int pcm_buffer[PCM_SIZE*2]; unsigned char mp3_buffer[MP3_SIZE]; lame_t lame = lame_init(); lame_set_in_samplerate(lame,44100); lame_set_VBR(lame,vbr_default); lame_init_params(lamE); do { read = fread(pcm_buffer,2*sizeof(short int),PCM_SIZE,pcm); if (read == 0) write = lame_encode_flush(lame,mp3_buffer,MP3_SIZE); else write = lame_encode_buffer_interleaved(lame,pcm_buffer,read,MP3_SIZE); fwrite(mp3_buffer,write,1,mp3); } while (read != 0); lame_close(lamE); fclose(mp3); fclose(pcm); } @catch (NSException *exception) { NSLog(@"%@",[exception description]); } @finally { [self performSELEctorOnMainThread:@SELEctor(convertMp3Finish) withObject:nil waitUntilDone:YES]; } } - (void) convertMp3Finish { }
但是这样做的结果只是带有噪音的.mp3.
> Here is example .caf file.
> And here is result .mp3 file.
所以我需要修复我的三个问题:
>在Objective C中从caf创建正确的mp3
>更改代码以将其用于wav文件
>并将其更改为能够在Swift中使用它
我知道iOS中编码和转换mp3有很多问题,但是我找不到Swift的例子,我找不到工作Objective C代码的例子(只是上面的代码).感谢帮助
以上是大佬教程为你收集整理的iOS Swift – 将.wav文件合并并转换为.mp3全部内容,希望文章能够帮你解决iOS Swift – 将.wav文件合并并转换为.mp3所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。