Convert Array of Floats to Wav File Swift [closed] - ios

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I want to convert an array of floats (one dimension) to an audio file -- then I want to send this audio file to a server with a put request, thus I need to convert it to Data.
How could I do this?? I have seen stack overflow posts about how to convert an array of floats to a wav file like this: Write array of floats to a wav audio file in swift
But I dont want to store anything, just convert it to a wav file, convert that to Data and send that to my db with a Put request. How can I do this? Thanks so much for your help!!

I recommend creating a temporary AVAudioFile to send to the server, and delete it when all data has been sent. This will prevent having to recreate the file in case the connection is dropped or has some other problem. It is also a high-level API that's easy to use.
If you want to avoid writing to a file, it can be done but will be much lower-level. You can create an AudioFileID with custom Data-based callbacks using AudioFileInitializeWithCallbacks, wrap that with ExtAudioFileWrapAudioFileID, and then write the floats using ExtAudioFileWrite after setting the client data format.

Related

Memory performance of storing image as base64 in UserDefaults [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I'm fetching an image from server and display it on the cover screen of App. After I fetch the image I store it in UserDefaults as Base64 string. Everytime I open the app, I convert base64 string to Image again and show it as background image. Usually image sizes are 1-2mb in png formats. However, I'm not sure If It will be a problem in terms of memory (converting to base64 and vise-versa).
1-) Does converting base64 to image when everytime App opens cause any problem in terms of performance (Memory leak)?
2-) Is there any better approach to store image file?
Step 1: Don't convert back and forth to base64. As Matt says, there's no reason for it. Your various storage options support binary data, so store it directly as binary data. (Data, even, since there are methods for writing Data objects to files in various formats.)
Step 2: Don't store large objects in UserDefaults. UserDefaults is intended to store small things like switch settings. Instead use a file, either in the Documents or the Caches directory.

How can live video be streamed from an iOS device to a server? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I want to be able to stream live video from an iOS device to a server. I tried to use an AVCaptureOutput that captures each frame as a CMSampleBuffer and appends it using an AVAssetWriter, but I don't know when or how to take the input from the file and send it to the server. How should it be formatted? How do I know when to send it?
Though i am not sharing any code with you, I am sharing my logic with you what i have done in one of my app.
First way(The easy one): There are lots of low cost third party library available for your use.
Second way(The hard one): Create small chunk of video for example 2sec or less, keep them in queue and upload it on the server(don't use afnetworking or http method it will slow down the process use some chat server like node.js or other). And keep one text file or db entry where you keep the track of the chunk file and its sequence. And once your first chunk is uploaded you can use ffmpg to make a video from the actual chunk, the more chunk you got add them in the main video file, and if you play the actual video on the device you don't have to do any more modification it will automatically fetch the new part once it is changed on the server.
Thank You. Hope it helps you.

Saving file to disk while I getting for TIdTCPServer / TIDTCPClient [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I want to go receiving a file via TIdTCPClient and receiving data that will be saved on disk, such as Skype. In Skype you send a file, the other person accepts and select somewhere to save the file begins to be transferred and the data that have been received will now be saved to disk, so the file is not in RAM. Does anyone know how to do this?
It's a little hard to work out precisely what the question is. But I think the issue is that you don't want to download the entire file to memory, and then write to disk.
I suspect that you are currently using TMemoryStream to receive the data. Doing so compels you to receive the entire file to memory. Avoid that quite simply by using TFileStream instead. Put the data to a file rather than memory.

How to convert CAF file to MP3 programmatically [duplicate]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I realize this question has been asked before, but I haven't seen an answer that works for my needs. Basically I have full length songs in .caf format but I need to be able to upload/download them from a server. Is it viable to do compression (to something like .mp3 or .wav) on the iPhone and then send them to the server? How would I go about doing this?
Refer to AudioConverterServices.. the function that does the magic trick is AudioConverterNew.. however note that you can only convert from a variable bit rate (VBR) file to PCM (lossless format), and from PCM to VBR.. so in your case you will have to convert the file from .caf to PCM, then from PCM to .mp3 or whatever format you want.
For a comprehensive example that illustrates all the steps necessary in doing an audio conversion.. download the free sample code for the book Learning Core Audio. You want chapter 6 sample code for audio conversion. (anyone who is serious about core audio should buy that book).
Mp3 encoding on an iPhone requires finding and using a non-Apple-provided library. There is nothing built-in that will do mp3 encoding, only AAC.
Using Lame, you can do this. Ther is no default function for this. It will also reduce the file size also. For 60 second audio file .caf will take approx 5mb - 10mb but after converting to .mp3 it will take 0.6mb to 0.7mb. Set 'Enable Bitcode' to 'NO' in build setting for new xocde, otherwise you will get error.
For sample code use this LINK.

Convert .caf to .mp3 on iPhone [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I realize this question has been asked before, but I haven't seen an answer that works for my needs. Basically I have full length songs in .caf format but I need to be able to upload/download them from a server. Is it viable to do compression (to something like .mp3 or .wav) on the iPhone and then send them to the server? How would I go about doing this?
Refer to AudioConverterServices.. the function that does the magic trick is AudioConverterNew.. however note that you can only convert from a variable bit rate (VBR) file to PCM (lossless format), and from PCM to VBR.. so in your case you will have to convert the file from .caf to PCM, then from PCM to .mp3 or whatever format you want.
For a comprehensive example that illustrates all the steps necessary in doing an audio conversion.. download the free sample code for the book Learning Core Audio. You want chapter 6 sample code for audio conversion. (anyone who is serious about core audio should buy that book).
Mp3 encoding on an iPhone requires finding and using a non-Apple-provided library. There is nothing built-in that will do mp3 encoding, only AAC.
Using Lame, you can do this. Ther is no default function for this. It will also reduce the file size also. For 60 second audio file .caf will take approx 5mb - 10mb but after converting to .mp3 it will take 0.6mb to 0.7mb. Set 'Enable Bitcode' to 'NO' in build setting for new xocde, otherwise you will get error.
For sample code use this LINK.

Resources