Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

streaming audio from iphone to server (HTTP streaming )

I use this code below to upload an audio file to server from disk. I want to upload the file as a stream directly from iphone mic to server .. using speakHere example we can capture the audio packets on the fly as they been recorded .

I tried many times and searched on it with no clue !!

NSString *fullPathToFile = [recordedAudioFilesDir stringByAppendingPathComponent:[NSString stringWithFormat:@"%i%i.wav",1,2 ]];


//..REMARK ,,change ayah froma nd ayah to and SurahID

 NSURL *url = [NSURL URLWithString:[NSString stringWithFormat: WEB_SERVICE_ADDRESS] ];




requestGlob = [[ASIHTTPRequest alloc] initWithURL:url]  ;
requestGlob.tag=[[NSString stringWithFormat:@"1000%i",1] intValue];
requestGlob.delegate=self;


[requestGlob setTimeOutSeconds:50];
[requestGlob setRequestMethod:@"PUT"];
[requestGlob setShouldContinueWhenAppEntersBackground:YES];
[requestGlob setShouldStreamPostDataFromDisk:NO];
[requestGlob setUseCookiePersistence:NO];
[requestGlob setUseSessionPersistence:NO];
[requestGlob setUseKeychainPersistence:NO];
[requestGlob setUploadProgressDelegate:self];



NSString *userName =@"[email protected]";

NSLog(@"username is %@",userName);
//hashed md5 password//e10adc3949ba59abbe56e057f20f883e
NSString *passowrd =@"q";
//NSLog(@"password is %@",passowrd);
 NSData *authData1 = [userName dataUsingEncoding:NSASCIIStringEncoding];
//encoded username

NSString *encodedUsername = [NSString stringWithString: [authData1 base64Encoding]];
//username + : + password

NSString *combined =[NSString stringWithFormat:@"%@:%@",  encodedUsername,passowrd ];
//encoded combined

NSString *encodedEveryThing= [NSString stringWithString:[[combined dataUsingEncoding:NSUTF8StringEncoding] base64Encoding]];
//the most important line since username and password are not arguments and its embedded in the header of the html

[requestGlob addRequestHeader:@"Authorization" value:[NSString stringWithFormat:@"Basic %@",encodedEveryThing]];




 [requestGlob appendPostDataFromFile:fullPathToFile];

[requestGlob startAsynchronous];

any ideas ?! thnx

like image 292
M.Othman Avatar asked Nov 30 '25 15:11

M.Othman


1 Answers

Well After digging and suffering .. I found a simple way to do that ..

and I uploaded my code to github-MOUploadAudioStreamer

Hope it helps somebody after all ..

like image 107
M.Othman Avatar answered Dec 02 '25 04:12

M.Othman



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!