台灣最大程式設計社群網站
∣
免費加入會員
∣登入
∣回首頁∣
您好
線上人數
1435
會員總數:
246690
討論主題:
190103
討論區
程式下載/上傳
科技新聞
專欄文章
會員中心
加值服務
外包接案
求職求才
登入
登出
歡迎您
免費
加入會員
討論區選單
新手必讀
我要提問!!
討論區
個人討論區
我的關注主題
我的黑名單
討論區EP英雄榜
專家等級說明
討論區常見問題
兌換發問點數QP
扣點申請加值服務
申請版主
開發工具
ASP
ASP.NET
C#
VB.NET
VB6
C/C++
PHP
Java
Java Script/ Node.js
AJAX / JSON / jQuery
其他語言
行動裝置開發
Android APP 開發
iOS APP/ swift 開發
Windows Phone APP
資料庫
ACCESS
MS SQL
MySQL
Oracle
其他DB
多媒體 / 網管
CSS/HTML5/Bootstarp
影像處理
office VBA / WinOS
Windows 伺服器
Linux / Unix
網管 / 資安 / VM
硬體 / 週邊 / 其他
綜合
求職求才
外包接案
心情甘苦談
網站經營 / 合夥 / 證照
建言 / 公告
文章區
專欄文章
科技新聞
Blog精華文章
討論區列表
>>
C#
>> C# 語音聊天功能
[]
[
我要回覆
]
C# 語音聊天功能
價值 : 30 QP
點閱數:1057 回應數:0
樓主
QQ_james
0
8
186
25
發送站內信
請各各大大幫忙
語音聊天程式有問題
它開始語音時只能3~10的語音有功能
再來就沒有聲音了
請大大幫幫忙了
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using System.Net; using System.Net.Sockets; using System.Threading; using Voice; using System.IO; namespace Void { public partial class Form5 : Form { Socket r; Thread t; bool connected = false; // System.ComponentModel.Container components = null; // private Socket serverSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); public Form5() { InitializeComponent(); //r = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); r = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp); t = new Thread(new ThreadStart(Voice_In)); } private void Voice_In() { byte[] br; //r.Bind(new IPEndPoint(IPAddress.Any, 6000)); r.Bind(new IPEndPoint(IPAddress.Any, int.Parse(this.txtUser.Text))); while (true) { br = new byte[16384]; r.Receive(br); m_Fifo.Write(br, 0, br.Length); } } private void Voice_Out(IntPtr data, int size) { //for Recorder if (m_RecBuffer == null || m_RecBuffer.Length < size) m_RecBuffer = new byte[size]; System.Runtime.InteropServices.Marshal.Copy(data, m_RecBuffer, 0, size); //Microphone ==> data ==> m_RecBuffer ==> m_Fifo r.SendTo(m_RecBuffer, new IPEndPoint(IPAddress.Parse(this.txtIP.Text), int.Parse(this.txtServer.Text))); } //********************************************************************************// private WaveOutPlayer m_Player; private WaveInRecorder m_Recorder; private FifoStream m_Fifo = new FifoStream(); private byte[] m_PlayBuffer; private byte[] m_RecBuffer; private void btnStart_Click(object sender, EventArgs e) { if (connected == false) { //MessageBox.Show("沒有連接者"); t.Start(); connected = true; } Start(); } private void btnStop_Click(object sender, EventArgs e) { Stop(); //Close(); } private void Start() { Stop(); try { WaveFormat fmt = new WaveFormat(44100, 16, 2); m_Player = new WaveOutPlayer(-1, fmt, 16384, 3, new BufferFillEventHandler(Filler)); m_Recorder = new WaveInRecorder(-1, fmt, 16384, 3, new BufferDoneEventHandler(Voice_Out)); } catch { Stop(); throw; } } private void Stop() { if (m_Player != null) try { m_Player.Dispose(); } finally { m_Player = null; } if (m_Recorder != null) try { m_Recorder.Dispose(); } finally { m_Recorder = null; } m_Fifo.Flush(); // clear all pending data } private void Filler(IntPtr data, int size) { if (m_PlayBuffer == null || m_PlayBuffer.Length < size) m_PlayBuffer = new byte[size]; if (m_Fifo.Length >= size) m_Fifo.Read(m_PlayBuffer, 0, size); else for (int i = 0; i < m_PlayBuffer.Length; i++) m_PlayBuffer[i] = 0; System.Runtime.InteropServices.Marshal.Copy(m_PlayBuffer, 0, data, size); // m_Fifo ==> m_PlayBuffer==> data ==> Speakers } private void Form5_Closing_1(object sender, System.ComponentModel.CancelEventArgs e) { t.Abort(); r.Close(); Stop(); } } }
搜尋相關Tags的文章:
[ 語音 ] ,
[ C# ] ,
[ 聊天 ] ,
[ 功能 ] ,
本篇文章發表於2017-08-28 15:58
目前尚無任何回覆
回覆
如要回應,請先
登入
.
|
網站導覽
|
網站介紹
|
4P點數說明
|
電子報
|
小舖活動
|
大事紀
|
廣告刊登
|
常見問題
|
聯絡我們
|
版權所有 ©copyright 2000 All Rights Reserved