質問編集履歴

1

コードを追記

2021/08/30 04:31

投稿

hodoru3sei
hodoru3sei

スコア284

test CHANGED
File without changes
test CHANGED
@@ -5,3 +5,99 @@
5
5
 
6
6
 
7
7
  音量を上げるにはどうしたら良いのでしょうか?
8
+
9
+
10
+
11
+ 現状のコードは以下です
12
+
13
+ ### コード
14
+
15
+
16
+
17
+ ```swift
18
+
19
+ class AudioRecorder {
20
+
21
+
22
+
23
+ private var audioRecorder: AVAudioRecorder!
24
+
25
+ internal var audioPlayer: AVAudioPlayer!
26
+
27
+
28
+
29
+ internal func record() {
30
+
31
+ let session = AVAudioSession.sharedInstance()
32
+
33
+ try! session.setCategory(AVAudioSession.Category.playAndRecord)
34
+
35
+ try! session.setActive(true)
36
+
37
+
38
+
39
+ let settings = [
40
+
41
+ AVFormatIDKey: Int(kAudioFormatMPEG4AAC),
42
+
43
+ AVSampleRateKey: 44100,
44
+
45
+ AVNumberOfChannelsKey: 2,
46
+
47
+ AVEncoderAudioQualityKey: AVAudioQuality.high.rawValue
48
+
49
+ ]
50
+
51
+
52
+
53
+ audioRecorder = try! AVAudioRecorder(url: getURL(), settings: settings)
54
+
55
+ audioRecorder.record()
56
+
57
+ }
58
+
59
+
60
+
61
+ internal func recordStop() -> Data?{
62
+
63
+ audioRecorder.stop()
64
+
65
+ let data = try? Data(contentsOf: getURL())
66
+
67
+ return data
68
+
69
+ }
70
+
71
+
72
+
73
+ internal func play() {
74
+
75
+ audioPlayer = try! AVAudioPlayer(contentsOf: getURL())
76
+
77
+ audioPlayer.volume = 10.0
78
+
79
+ audioPlayer.play()
80
+
81
+ }
82
+
83
+
84
+
85
+ internal func playStop() {
86
+
87
+ audioPlayer.stop()
88
+
89
+ }
90
+
91
+
92
+
93
+ private func getURL() -> URL{
94
+
95
+ return FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)[0].appendingPathComponent("sound.m4a")
96
+
97
+ }
98
+
99
+ }
100
+
101
+
102
+
103
+ ```