java 将数据转换为声音并返回
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4483662/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Convert Data to sound and back
提问by Shawn Mclean
Are there libraries out there that can convert data (text files, etc) to sound and back to the original data?
是否有可以将数据(文本文件等)转换为声音并返回原始数据的库?
The sound can be transmitted any medium I wish, whether radio, etc. I just need to store data in sound files.
声音可以通过任何我希望的媒体传输,无论是收音机等。我只需要将数据存储在声音文件中。
Scenario:
设想:
step1:Convert a .docx file with embedded images to .wav.
步骤 1:将带有嵌入图像的 .docx 文件转换为 .wav。
step2:Send over a radio wave.
步骤 2:通过无线电波发送。
step3:Convert this .wav back to the .docx file with the embedded images.
步骤 3:将此 .wav 转换回带有嵌入图像的 .docx 文件。
This concept can be applied to any data.
这个概念可以应用于任何数据。
Technology:
技术:
.netor java
.net或 java
采纳答案by Andiih
I think the medium is important, as are other factors such as the size of the files and the transmission time available. A simple algorithm would be to convert your files to text (UUENCODE should do that trick) then convert to morse code : http://www.codeproject.com/KB/vb/morsecode.aspx
我认为媒体很重要,其他因素也很重要,例如文件的大小和可用的传输时间。一个简单的算法是将您的文件转换为文本(UUENCODE 应该这样做)然后转换为摩尔斯电码:http: //www.codeproject.com/KB/vb/morsecode.aspx
Morse gives you a simple alphabet able to survive transmission over a fairly noisy radio channel.
Morse 为您提供了一个简单的字母表,能够在相当嘈杂的无线电频道中进行传输。
If your carrier is cleaner a conversion of your UUEncoded file into a series of frequencies one per character would probably also work, and be easy enough to decode at the other end, Frequency Analyzer in C#
如果您的运营商更干净,将您的 UUEncoded 文件转换为每个字符一个的一系列频率可能也可以工作,并且很容易在另一端解码,C# 中的频率分析器
回答by Dimitri Georganas
The problem is that the data in a word document doesn't necessarily make decent sound. If you pick a 1.8kHz carrier and use the binary contents of the word document to modulate the volume or the frequency (AM or FM) the result will be messy and hardly to decode.
问题在于,word 文档中的数据不一定能发出像样的声音。如果您选择 1.8kHz 载波并使用 word 文档的二进制内容来调制音量或频率(AM 或 FM),结果将是混乱且难以解码的。
But if you save the document as a bitmap, you can use the pixel values to modulate the volume of the carrier wave.
但是,如果将文档保存为位图,则可以使用像素值来调制载波的音量。
We've been sending pictures (not just black/white but greyscale and color (three different separations of the image, r, g and b) over phonelines using this method for many years before modems and the internet took off.
在调制解调器和互联网兴起之前,我们多年来一直使用这种方法通过电话线发送图片(不仅仅是黑白,还有灰度和彩色(图像的三种不同分离,r、g 和 b)。
The fun part is that you can broadcast data this way. The sound can be received by more than one receiver at the same time. There's no error correction, but as you deal with visual data, you don't have to worry about a few pixels getting lost. It's similar to old fax protocols.
有趣的是,您可以通过这种方式广播数据。声音可以同时被多个接收器接收。没有纠错功能,但在处理视觉数据时,您不必担心丢失几个像素。它类似于旧的传真协议。
回答by Sudantha
Best way is to convert the audio file into binary and store in a file type you specify.
最好的方法是将音频文件转换为二进制文件并存储在您指定的文件类型中。
Try out the AudioInputStream Classin Java
试用Java 中的 AudioInputStream 类
回答by Lucero
Does the audio file need to be convertible using lossy compressors (MP3 etc.)? If not, you can just add a WAV container around any binary data and you'll be fine. Otherwise it gets more difficult, and you need to ensure that the audio is audible (in a reasonable frequency range when played) and be tolerant enough on the frequency detection to match the output of lossy codecs.
音频文件是否需要使用有损压缩器(MP3 等)进行转换?如果没有,你可以在任何二进制数据周围添加一个 WAV 容器,你会没事的。否则它会变得更加困难,您需要确保音频是可听的(播放时在合理的频率范围内)并且对频率检测有足够的容忍度以匹配有损编解码器的输出。
回答by Arvin
You could try to use the magnetic card technology for your files, I'm also trying to do this on android. Any data can be converted to byte into a string of characters it very possible with java and android. then use the Encoding mechanism of Magnetic Cards API to encode the string to sound. Then you can just use the vice versa, convert the sound into string convert string into byte and save the data. It's just it takes time to convert both ways but it is feasible, I'm trying to do this so that any one with unlimited voice connection can transfer files or in the future browse the internet just through calling the other number. I hope I gave you some idea.
您可以尝试对您的文件使用磁卡技术,我也在尝试在 android 上执行此操作。任何数据都可以转换为字节为字符串,这在java和android中是很有可能的。然后使用磁卡 API 的编码机制将字符串编码为声音。然后你可以反之亦然,将声音转换为字符串,将字符串转换为字节并保存数据。只是两种方式转换都需要时间,但它是可行的,我正在尝试这样做,以便任何具有无限语音连接的人都可以传输文件,或者将来只需拨打另一个号码即可浏览互联网。我希望我给了你一些想法。
回答by Paul J R
To give what I think is a better response to all of the above, have a look at packet radio and the various bits that correspond to it AX.25 is a good example and there are a number of implementations for it. POCSAG is also another good implementation. Both have libraries available for many different languages and have been around for quite a long time.
为了给出我认为对上述所有内容的更好响应,请查看分组无线电以及与其对应的各种位 AX.25 是一个很好的示例,并且有许多实现方式。POCSAG 也是另一个很好的实现。两者都有可用于许多不同语言的库,并且已经存在了很长时间。
Other example include things like WEFAX (weather fax), HFFax, SSTV (slow scan tv), etc.
其他示例包括 WEFAX(天气传真)、HFFax、SSTV(慢扫描电视)等。
You can think of them all as being similar to the old school phone line modem type encoders and decoders that run around the 300-2400baud
您可以将它们全部视为类似于运行在 300-2400 波特附近的老式电话线调制解调器类型的编码器和解码器