I'm getting List<int> as RAW data from recorder plugin for Android and iOS, I want to display Actual text from the bytes, The data is stream of system mic.
Any way to get text from bytes?
Raw data detail:
SampleRate: 44100,
ChannelConfig: MONO-16,
AudioSource: SYSTEM-MIC
Note: I'm already using SpeechToText plugin and aware about it, But I fill that at some-point which is dropping words hence I want to try something else.
Any help will be appreciated.
import 'package:mime/mime.dart';
String? lookupMimeType(String path, {List<int>? headerBytes})
You can use ı think.
var mimeString = lookupMimeType();İf you fill the parameter it works. You can use directly your audio file's path.
Related
I need to load/save the number of coins a user has earned in my Unity game with saved games for Play Games Services.
There is an example on how to save an image on this page: https://developer.android.com/games/pgs/unity/saved-games#write_a_saved_game
Can someone tell me how I can load/save a number instead of an image?
To be precise, I wouldn't say you are exactly saving an image. I mean, you do save it, but only as a cover for your game save file and I don't know if you can retrieve it (maybe you can, I haven't checked that really).
Probably the most important part of using google play save system is byte[] savedData argument. It's just a byte array, and it's up to you what are you going to pass there and how are you going to interpret that data on game load.
There are a lot of ways you could approach it. I personally create a custom GameSave object with all my data that I want to save, then I serialize it using JsonUtility.
string json = JsonUtility.ToJson(gameSave);
After that, I use MemoryStream and BinaryFormatter to convert the data in my json to byte array:
MemoryStream memoryStream = new MemoryStream();
BinaryFormatter binaryFormatter = new BinaryFormatter();
binaryFormatter.Serialize(memoryStream, json);
byte[] data = memoryStream.GetBuffer();
Then you would have to pass that data to savedGameClient.CommitUpdate method as an argument.
Of course, that's just one of the ways of doing that, you can send something else than json from serialized class object.
Other stuff is pretty well documented, so once you handle that, you should manage to do the rest.
The new Flutter 3.3 deprecates the method load of class ImageProvider and now some my code became not working because load had a parameter bytes of type Uit8List but loadBuffer has a parameter buffer of ImmutableBuffer.
I used Uint8List to decode image using image package
final bytes = img.decodeImage(bytes); // bytes is instance of Uit8List
The complete code can be read from the article Remove a color from an image in Flutter starting from section 4. Decode.
And now I need to convert ImmutableBuffer to Uint8List. Does someone know how to do this?
Currently I am saving game progress in a file in JSON format. Each time player completes the level a new entry will be added to JSON file as follow "level_N":{"score":234,"points":22},
this file will be saved at the end of Level complete. Consider scenario in which player reaches level 2345 or so, In that case saving to the file on level complete takes considerably longer time in some mobile devices. how to manage saving such a large amount of data ? do I have to use some other formats ? or do i have to save each level detail in separate file ?
PlayerPrefs is the easiest way to save data. It’s designed to handle basic data types (int, string, float) and works like a dictionary, so you can simply store JSON string as key-value pairs. And there is no size limit on iOS or Android (in webplayer it's limited to 1MB).
// read
PlayerPrefs.GetString(string key, string value);
// write
PlayerPrefs.SetString(string key, string value);
// load and update
const saveKey = "level_N";
Private void SaveProgress()
{
string saveValue = "your JSON string";
string loadValue = PlayerPrefs.GetString(saveKey);
if (!saveValue.Equals(loadValue))
{
PlayerPrefs.SetString(saveKey, saveValue);
PlayerPrefs.Save();
}
}
User data will be automatically written to disk during OnApplicationQuit(), but you may want to use PlayerPrefs.Save() in case your game crashes.
Having said that, saving a large amount of data to PlayerPrefs on mobile devices might be slow. So if you want to improve your game performance or need more space, you can use Application.persistentDataPath to save data to a public directory on the device. Similar to PlayerPrefs, data is not cleared when app is updated.
FileStream file = File.Open(Application.persistentDataPath + "/gameInfo.dat", FileMode.Open);
You can use PlayerPrefs class to save to save the local data.
In your case, you can trun your json to string then call PlayerPrefs.SetString to save/PlayerPrefs.GetString to get.
PlayerPrefs is always a good choice for local data managing but if you planning to add online features to your game, I recommend you to take a look at Firebase Realtime Database for sync json data with offline support. And let the firebase manage performance issues on mobile devices. Here you can see how to integrate Firebase Database to your Unity project easily.
I have extracted the audio data from .m4a file using mp4v2 library (sample-by-sample). Does this library have function that decodes the data? Anybody with experience with this library and can provide some help?
The documentation says:
MP4ReadSample function reads the specified sample from the specified track.
Typically this sample is then decoded in a codec dependent fashion and
rendered in an appropriate fashion.
I am interesed in decoding the output.
Thanks in advance.
You tagged MP4(video data) and M4A(audio data). Since you are extracting from M4A, I can only imagine you actually have either AAC or MP3 audio data.
Each extracted sample (bytes) is audio frame.
To make a playable MP3 file : Simply join all MP3 frames' bytes together. Save as .mp3 to play later.
To make a playable AAC file : For each AAC frame, first create an ADTS header (7 bytes) followed by that frame's data. You can test your header bytes here (site shows what your byte values mean). When all your AAC frames each begin with an ADTS header, simply save as .aac to play later using some audio payer code.
I have researched everything and the answer is NO. There is no decoder in mp4/mp4v2 libraries. One has to use some other library to do that.
I'm building an App with actionscript 3.0 in my Flash builder. This is a followup question this question.
I need to upload the bytearray to my server, but the function i use to convert the bitmapdata to a ByteArray is super slow, so slow it freezes up my mobile device. My code is as follows:
var jpgenc:JPEGEncoder = new JPEGEncoder(50);
trace('encode');
//encode the bitmapdata object and keep the encoded ByteArray
var imgByteArray:ByteArray = jpgenc.encode(bitmap);
temp2 = File.applicationStorageDirectory.resolvePath("snapshot.jpg");
var fs:FileStream = new FileStream();
trace('fs');
try{
//open file in write mode
fs.open(temp2,FileMode.WRITE);
//write bytes from the byte array
fs.writeBytes(imgByteArray);
//close the file
fs.close();
}catch(e:Error){
Is there a different way to convert it to a byteArray? Is there a better way?
Try to use blooddy library: http://www.blooddy.by . But i didn't test it on mobile devices. Comment if you will have success.
Use BitmapData.encode(), it's faster by orders of magnitude on mobile http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/BitmapData.html#encode%28%29
You should try to find a JPEG encoder that is capable of encoding asynchronously. That way the app can still be used while the image is being compressed. I haven't tried any of the libraries, but this one looks promising:
http://segfaultlabs.com/devlogs/alchemy-asynchronous-jpeg-encoding-2
It uses Alchemy, which should make it faster than the JPEGEncoder from as3corelib (which I guess is the one you're using at the moment.)
A native JPEG encoder is ideal, asynchronous would be good, but possibly still slow (just not blocking). Another option:
var pixels:ByteArray = bitmapData.getPixels(bitmapData.rect);
pixels.compress();
I'm not sure of native performance, and performance definitely depends on what kind of images you have.
The answer from Ilya was what did it for me. I downloaded the library and there is an example of how to use it inside. I have been working on getting the CameraUI in flashbuilder to take a picture, encode / compress it, then send it over via a web service to my server (the data was sent as a compressed byte array). I did this:
by.blooddy.crypto.image.JPEGEncoder.encode( bmp, 30 );
Where bmp is my bitmap data. The encode took under 3 seconds and was easily able to fit into my flow of control synchronously. I tried async methods but they ultimately took a really long time and were difficult to track for things like when a user moved from cell service to wifi or from tower to tower while an upload was going on.
Comment here if you need more details.