如何使Android手机作为一个蓝牙耳机? [英] How to make Android phone as a bluetooth headset?

查看:540
本文介绍了如何使Android手机作为一个蓝牙耳机?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是的,我知道的Andr​​oid已经实现了蓝牙耳机 个人,但它在音频网关的角色,而不是在耳机中的作用。

Yes, I know Android has already implemented the Bluetooth Headset Profile, but it is in Audio Gateway Role, not in HeadSet Role.

我想要做的是制定有关Android手机的应用程序, 将作为一个蓝牙耳机,因此它可以通过连接到我的笔记本 蓝牙。 当我尝试打电话给别人,我可以用我的手机拨打他,我 应用程序将通过蓝牙转发的声音,我的笔记本电脑, 并在笔记本电脑上运行另外一个应用程序将获得语音数据 并转发给的Skype或GTalk的或部分的VoIP程序别的。

What I want to do is develop an application on Android phone which will act as a bluetooth headset, so it can connect to my laptop by bluetooth. When I try to call somebody, I can use my phone to dial him, and my application will forward the voice through bluetooth to my laptop, and one other application running on laptop will get the voice data and forward them to Skype or GTalk or some VoIP program else.

在换句话说,我怎么能实现耳机配置文件的耳机 角色在Android手机?在此先感谢!

In other words, how can I implement the Headset Profile in Headset Role on Android phone? Thanks in advance!

推荐答案

从Android方面,我认为最好的解决办法就是打开您的计算机连接到服务:

From the android side, I think the best solution is to open the connection to the service in your computer:

URL url = new URL("http://192.186.0.1/path/to/service");
URLConnection connection = url.openConnection();

将它作为一个OutputStream:

Get it as an OutputStream:

OutputStream out = new BufferedStream(connection.getOutputStream());

然后用 AudioRecord 发送,虽然记录的数据:

and then use a AudioRecord to send though the recorded data:

public static final int DEFAULT_SAMPLE_RATE = 8000; 
private static final int DEFAULT_BUFFER_SIZE = 4096; 
private static final int CALLBACK_PERIOD = 4000;

AudioRecord recorder = new AudioRecord(MediaRecorder.AudioSource.DEFAULT, 
            DEFAULT_SAMPLE_RATE, AudioFormat.CHANNEL_CONFIGURATION_DEFAULT, 
            AudioFormat.ENCODING_DEFAULT, DEFAULT_BUFFER_SIZE);
recorder.setPositionNotificationPeriod(CALLBACK_PERIOD);

int bytesRead = 0;
ByteBuffer buffer = ByteBuffer.allocateDirect(DEFAULT_BUFFER_SIZE);
while ((bytesRead = recorder.read(buffer, DEFAULT_BUFFER_SIZE)) > 0) {
    out.write(buffer.array(), 0, bytesRead);
}

这一切都应该在课程的一个单独的线程来完成,以避免崩溃的应用程序和机制来处理时,记录停止或连接中断。另外,我是pretty的确定它应该通过wifi虽然我不知道这是否将是相同的带有蓝牙(虽然大部分的设备与英国电信的有wifi现在是一个天,你会得到更多的带宽)

All this should be done on a separate thread of course to avoid crashing the app and a mechanism to handle when the recording stops or the connection is lost. Also, I'm pretty sure it should work over wifi although I am not sure if it will be the same with bluetooth (although most devices with BT have wifi now a days and you get more bandwidth)

我,所以我不是100%肯定它会工作没有测试code。

I haven't tested this code so I'm not 100% sure it will work.

接下来的事情将是本机传输音频到愿望应用上,但是这上面我的经验。我想你会做一个虚拟驱动器或类似的东西。 还必须做逆机制,从桌面应用程序发送到手机音频(我在那一部分,而有兴趣的,因为将是一个不错的无线耳机看电影也一样)。

The next thing will be on the machine to transfer the audio into the desire app, but that's above my experience. I imagine you will have to do a virtual driver or something like that. Also will have to do the inverse mechanism for the audio sent from the desktop app into the phone (I'm rather interested on that part since would make a nice wireless headset for watching movies as well).

下面是我的2美分;我急切地想知道,如果它的工作原理。 ;)

Here are my 2 cents; I am eager to know if it works. ;)

这篇关于如何使Android手机作为一个蓝牙耳机?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆